hi,
pls consider the following if statement
if [ -z $(echo $1|sed 's/[0123456789]//g') ]
then
........
else
.......
when i execute the script i am getting the following error
'(' unexpected
I am not able to find the mistake.
could anybody tell where i did mistake.
cheers
RRK
I can run your code in ksh without any problem:
#!/bin/ksh
if [ -z $(echo $1 | sed 's/[0-9]//g') ]; then
echo "Numeric"
else
echo "Non-Numeric"
fi
Output:
$./test 123
Numeric
$./test a123
Non-Numeric
Which shell you are using?
I can only suggest you to check the version of ksh because i have tested your code at ksh93, if you are too at ksh93 then i'm aslo blank!!!
Regards,
Tayyab
Put a
set -o
in front of the "if" statement and post the results. The output from "set -o" will settle which shell is processing that "if" statement.
grial
January 10, 2007, 3:04am
6
Try this instead and let's see:
if [ -z `echo $1|sed 's/[0123456789]//g'` ]
putting back quotes also giving the same error.
anbu23
January 10, 2007, 4:07am
8
Can you show the trace of your script?
grial
January 10, 2007, 4:55am
9
mmmm, I've tested tayyabq8,s script on AIX 5.2 and:
$ ./kk2.sh 123
./kk2.sh[2]: test: 0403-004 Specify a parameter with this command.
Non-Numeric
That's fixed this way:
if [[ -z $(echo $1 | sed 's/[0-9]//g') ]]; then
(...)
Have a look at:
All Unix, Linux and other Unix-like operating systems are families of computer operating systems derived from the original Unix System from AT&T Bell Laboratories. Today, the largest Unix descendent directly certified as UNIX is macOS by Apple....
from Perderabo.
johnf
January 10, 2007, 4:58am
10
tayyabq8:
I can run your code in ksh without any problem:
#!/bin/ksh
if [ -z $(echo $1 | sed 's/[0-9]//g') ]; then
echo "Numeric"
else
echo "Non-Numeric"
fi
Output:
$./test 123
Numeric
$./test a123
Non-Numeric
Which shell you are using?
I have tested the above on 5.3 AIX with no modifications and it works fine as it should as there is nothing wrong with it. Why the original does not work is a mystery!
aigles
January 10, 2007, 5:18am
11
Another way to test for numeric string
#!/bin/ksh
if [[ $1 = *([0-9]) ]]
then
echo "Numeric"
else
echo "Non-Numeric"
fi
Jean-Pierre.
It's also working fine in the bash shell too.
hi,
pls consider the following if statement
if [ -z $(echo $1|sed 's/[0123456789]//g') ]
then
........
else
.......
when i execute the script i am getting the following error
'(' unexpected
I am not able to find the mistake.
could anybody tell where i did mistake.
cheers
RRK
try by using double quotes instead of single quotes for the sed command pattern and post reply
If after changing
if [ -z $(echo $1|sed 's/[0123456789]//g') ]
to
if [ -z `echo $1|sed 's/[0123456789]//g'` ]
you are continuing to get
'(' unexpected
then you have misdiagnosed your problem. The error message and the "if" statement have nothing to do with one another. If you continue to believe otherwise, extract that "if" statement and produce a self-contained 3 or 4 line script that reproduces the error message. Post the short script and the error message and someone will help you fix it.