这个C Shell脚本怎么了? [英] Whats wrong with this C shell script?

查看:86
本文介绍了这个C Shell脚本怎么了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为bash脚本在这里提到

I am trying to write a C shell equivalent script for the bash script mentioned here.

这就是我所拥有的:

#! /bin/tcsh

set now=`date +%Y%m%d%H%M.%S`
if (( ! -f "./cache" ) || (-n  "`find ./monme -newer ./cache`" ))
then
    touch cache -t "$now"
    echo "new files added" | mail -s "new build" myemail@myserver.com
endif

这是错误我得到

$ ./scr
if: Badly formed number.
$

此页面提到 C壳中的数字必须是整数,所以我尝试了

This page mentions that "Numbers in the C-shell must be integers", so I tried

set now=`date +%Y%m%d%H%M`

但我仍然遇到相同的错误。

but I get the same error still.

推荐答案

我将您的脚本缩减为:

I cut down your script to this:

#! /bin/tcsh

if ( -n  "`find ./monme -newer ./cache`" ) then
    echo hello
endif

这给出了相同的错误。我认为罪魁祸首是

This gives the same error. I think the culprit is

-n  "`find ./monme -newer ./cache`"

-n 应该做什么?我认为它想要一个数字,但还有其他内容...

What is -n supposed to do? I think it wants a number, but gets something else...

更新:bash中的-n表示字符串长度不零。在我的tcsh版本中,就像这样使用==一样容易替换:

Update: -n in bash means "length of string is non-zero". In my version of tcsh it is as easy to replace as to use == "" like this:

if (( ! -f "./cache" ) || ("`find ./monme -newer ./cache`" != ""))
then
    touch cache -t "$now"
    echo "new files added" | mail -s "new build" myemail@myserver.com
endif

试一试,看看如果可行。

Try that and see if it works.

这篇关于这个C Shell脚本怎么了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆