Can anyone help me with a general shell scripting question? I need to be able
to verify an argument passed via command line and ensure that the value is
numeric. Is there any way to do this?
Thanks
Thanks
> Thanks
if [ X$(echo $SOMEVAR|tr -d "[0-9]") = X ]
then
echo "\$SOMEVAR is numeric or undefined"
else
echo "\$SOMEVAR is not numeric"
fi
should do the trick, assuming SOMERVAR has been defined and is not an empty
string, though I haven't tested this.
Ta
Ta
[[ "$1" = +([0-9]) ]]
cheers,
gary
>Thanks
> Can anyone help me with a general shell scripting question? I need to be able
> to verify an argument passed via command line and ensure that the value is
> numeric. Is there any way to do this?
> Thanks
--
Chris
I just need it to verify a integer value, no + or - or anything else to worry
about.
If anyone else has some other need way please pass it along.
Thanks
>Can anyone help me with a general shell scripting question? I need to be able
>to verify an argument passed via command line and ensure that the value is
>numeric. Is there any way to do this?
>Thanks
>Thanks
Which numeric formats did you have in mind?
This is not a trivial question. :-)
Chuck Demas
Needham, Mass.
--
Eat Healthy | _ _ | Nothing would be done at all,
Die Anyway | v | That no one could find fault with it.
> I just need it to verify a integer value, no + or - or anything else to worry
> about.
> If anyone else has some other need way please pass it along.
> Thanks
>>Can anyone help me with a general shell scripting question? I need to be able
>>to verify an argument passed via command line and ensure that the value is
>>numeric. Is there any way to do this?
>>Thanks
case $var in
*[!0-9]*) # non-numeric;;
'') # empty string;;
*) # numeric;;
esac
This is portable for all bournish shells. Shells that support
extended globbing like ksh and bash 2 can use the following syntax:
if [[ $var = +([0-9]) ]];then echo integer;...
You need to turn on extended globbing in bash with shopt:
shopt -s extglob
--
Dan Mercer
Opinions expressed herein are my own and may not represent those of my employer.
# isnum returns True if its argument is a valid number.
# The first pattern requires a digit before the decimal
# point, and the second after the decimal point.
# bsh: does not acount for: 0e0 (no decimal point)
case $1 in
(?([-+])+([0-9])?(.)*([0-9])?([Ee]?([-+])+([0-9])))
return 0 ;;
(?([-+])*([0-9])?(.)+([0-9])?([Ee]?([-+])+([0-9])))
return 0 ;;
*) return 1 ;;
esac
-Brian
1. How can I pass a command line argument to an aliased command?
How can I pass a command line argument to an aliased command?
In this example, I want to pass a candidate directory name as a command line
argument and have it processed by the "dir" alias script.
For example:
arvant02:/opt/vantive8> alias dir='ll -F omu | egrep ^d '
arvant02:/opt/vantive8> dir
drwxrwxr-x 2 vantive dba 2048 Aug 9 2001 apps_ora8/
drwxrwxrwx 2 vantive dba 2048 Apr 26 11:46 backup/
drwxrwxrwx 2 oracle dba 96 Oct 9 2001 core_22352/
drwxrwxrwx 2 vantive dba 2048 Apr 26 11:38 data/
drwxrwxrwx 2 vantive dba 4096 Apr 26 11:46 log/
drwxrwxr-x 8 vantive dba 96 Aug 9 2001 movebinary/
drwxrwxr-x 3 vantive dba 96 Apr 26 11:32 omudata/
drwxrwxr-x 2 vantive dba 2048 Aug 9 2001 views/
arvant02:/opt/vantive8>
The above alias lists those directories belonging to the subdirectory omu.
I hardcoded the "omu" directory into the dir alias script.
If,however, I want to replace the hardcoded "omu" subdirectory value with a
variable that I pass in as a command line argument to the alias command
"dir", such as, dir sub_dir <enter>, how would I alter the alias script to
enable this?
Mark
2. another shit post from flattie
3. ?how to verify mksysb backup at command line
4. Does solaris have a built-in bootloader...?
5. Verify password from command line
7. HELP - RH Apache and command line arguments
8. : NeXT display on X11/DGS? NSHosting under Linux? HELP!
9. insmod command line argument
10. pagenumber as command line argument
11. Command line arguments, indirectly
12. How to mask command line arguments in C shell?
13. Quoting Last Command Line Argument