Scripting 这个C shell脚本有什么问题?

Scripting 这个C shell脚本有什么问题?,scripting,shell,csh,tcsh,Scripting,Shell,Csh,Tcsh,我正在尝试为bash脚本编写一个与C shell等效的脚本 这就是我所拥有的: #! /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

我正在尝试为bash脚本编写一个与C shell等效的脚本

这就是我所拥有的:

#! /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-shell中的数字必须是整数”,所以我尝试了

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

但是我还是遇到了同样的错误。

我将您的脚本缩减为:

#! /bin/tcsh

if ( -n  "`find ./monme -newer ./cache`" ) then
    echo hello
endif
这就产生了同样的错误。我认为罪魁祸首是

-n  "`find ./monme -newer ./cache`"
-n
应该做什么?我想它想要一个数字,但得到的是别的

更新:-n在bash中表示“字符串长度非零”。在我的tcsh版本中,替换与使用==“”一样容易,如下所示:

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

试试看它是否有效。

这部分的间距
(-n…)
括号和破折号n之间的间距,然后也应该在同一行上,好像?@tommieb75:仍然是相同的错误。@Lazer:最后一枪<代码>(-n eval(find./monme-newer./cache`))“@tommieb75:if((!-f./cache”)| |(-n eval(
find./monme-newer./cache
”)然后=>
如果:格式错误的数字。
@Lazer:dang。。。。为你祈祷。。。一个比我知识更渊博的人希望能给你正确的答案。。。。我尽了最大的努力:)@Peter:我自己以前没用过。从中,“-n解析命令但不执行它们。这有助于检查shell脚本的语法”。据我所知,-n是csh在运行它时的一个选项(如在
tcsh-n“echo hello there”
),而不是在类似的if中可以使用的东西-n在if中似乎有某种含义,但我无法在我的手册页中快速找到它。好的,我看到您是从bash脚本中逐字记录下来的。在bash中,或者更确切地说是test命令,-n表示以下字符串的长度应为非零。因为这在tcsh中不起作用,所以您必须在tcsh中找到等效项,或者稍微重新构造代码。@Peter:当然,我会等一段时间,以防有人提出一些好的建议。谢谢编辑,Lazer:)在此之前我的回答有点愚蠢。