Whats wrong with this C shell script?

前提是你 提交于 2019-12-11 03:37:41

问题


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

This is what I have :

#! /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

and this is the error I get

$ ./scr
if: Badly formed number.
$

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.


回答1:


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`"

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

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.



来源:https://stackoverflow.com/questions/3692137/whats-wrong-with-this-c-shell-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!