Domanda

i am beginner in writing scripts in csh/tcsh so that's why i need you help. I have to find out if arguments of my script are written correctly on stdin. I have some script for example called 'first_script' that must have arguments in this form: first_script -d (and this is my problem) ---> how can i find out, if there's number (integer - not only digit) after -d argument? Thanks a lot for helping me.

È stato utile?

Soluzione

Processes can only pass strings as arguments, so what you will get will always be a string. It's up to you to interpret the value as what you need (e. g. an integer).

In your case I think checking if the given string consists solely of digits would solve your issue. There are many ways to do this check, but here is my favorite:

if ( "$1" == "-d" ) then
   expr "$2" : '[0-9]*$' > /dev/null && echo "We have a number" || echo "We have a non-number"
endif
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top