i trying catch typeset error below shell script test.sh:
shell script
typeset -i int int=2 echo $int int=asd || echo "type mismatch" but getting output as:
output
./test.sh 2 ./test.sh[4]: asd: bad number required result
./test.sh 2 ./test.sh[4]: asd: bad number **type mismatch** i using following machine:
bash --version gnu bash, version 3.2.51(1)-release (sparc-sun-solaris2.10) copyright (c) 2007 free software foundation, inc. please suggest me change need make in script. need way make sure input parameter int. , have use typeset along exception handling.
try using eval:
typeset -i int # using name "int" seems asking trouble! eval int="$1" || echo "type mismatch" >&2 the issue in line int=asd || ..., first simple command evaluate true required standard, since no command given. variable assignments take place in current shell, no command given , results specified in section 2.9.1 :
if there command name, execution shall continue described in command search , execution . if there no command name, command contained command substitution, command shall complete exit status of last command substitution performed. otherwise, command shall complete 0 exit status.
Comments
Post a Comment