View Full Version : [SOLVED] alternative to bash in tcsh

October 19th, 2011, 11:59 PM

I have following lines in bash, the lines are inside while

if [[ "$2" == +([0-9]) ]]
then depth=$2
else exit 1
The code check wheather the $2 is a number with unless 1 digit

and I want to ask how can this be done in tcsh?

So far I tried everything that I could came up(and it was a lot of ideas) but none of it has worked.
I 've also googled a lot and find out that tcsh's "if" uses some glob-expresion when it comes to pattern, and I haven't been able to find something in the glob-expresions that would do the same stuff as that "if" above, I tried but I can't find solution on my own, so I am asking for your help.


October 20th, 2011, 12:48 AM
Hi again

I have solved it ;)

if ( $i > $#argv ) then
exit 1
expr "$argv[$i]" + 1 >& /dev/null
if ($status != 0) then
exit 1
set depth = $argv[$i]


the expr will try to add 1 to something in $argv[$i] and wheather it success or fail is stored in special shell variable $status and the first if is for the case when there is no input