0

Need to apply it on csh.

to check if the inputted $2 is not number nor the word "all"

if ($#argv == 2 && ($2 != all && $2 != **any number**)) then
   echo "wrong parameter"
1
if ( $#argv == 2 && $2 != 'all' && $2 !~ ^[0-9]+$ ) then
   echo "wrong parameter"
endif

Tested on AIX 7.1 - CSH 1.20.3.5

  • Is that supposed to be $#argv and not just $argv? – HalosGhost Oct 20 '14 at 4:47
  • $argv returns all the arguments, whereas $#argv returns the number of arguments – DarkHeart Oct 20 '14 at 5:14
  • Ahh, so that's a csh-specific thing then. Good to know! – HalosGhost Oct 20 '14 at 5:15
  • what is the difference between the one with the + and *? ^[0-9]+$ and ^[0-9]*$? – user68890 Nov 3 '14 at 8:47
  • '+' means 1 or more. '*' means 0 or more. The latter will match an empty string. – DarkHeart Nov 4 '14 at 2:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.