![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Whats wrong in the script? | nehagupta2008 | UNIX for Dummies Questions & Answers | 1 | 06-02-2008 06:24 AM |
| tell me whats wrong in this? | nadman123 | Shell Programming and Scripting | 1 | 04-10-2008 01:11 AM |
| Whats wrong in this Script ??? | varungupta | UNIX for Advanced & Expert Users | 4 | 08-31-2007 04:02 AM |
| Whats wrong with this script? | kayarsenal | Shell Programming and Scripting | 2 | 08-25-2006 09:58 AM |
| whats wrong with this awk??? | george_ | Shell Programming and Scripting | 5 | 04-04-2006 04:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Besides the "if" syntax error, you have a major misunderstanding on what can be inside the test brackets
Code:
user=$1
if [ "$user | grep [0-9]" -eq 0 ]
then
echo "No"
else
echo "Yes"
fi
Code:
$ ksh -x test.sh bob + user=bob + [ bob | grep [0-9] -eq 0 ] test.sh[3]: bob | grep [0-9]: 0403-009 The specified number is not valid for this command. + echo Yes Yes |
|
||||
|
Sorry, I was only prompting you to examine the code (through the trace) since the error is clear. I really don't know what you are trying to acheive with "$user | grep [0-9]". Nothing will be "grep'd" because KSH doesn't know that you are trying to grep anything. KSH thinks that this is one big string. Your test needs to be along the lines of this:
[ $(some shell commands like piped through grep) -eq 0 ] You are going to run into more problems since "$user" is treated as a command when inserted into $(); I'm certain that you want to echo this through grep. |
|
||||
|
Hi,
Apologies, think we got off on the wrong foot, i've just started to learn scripting, it was just to test the word entered in $1 if it started with a digit or not, but i wanted to use an if statement to do it..... Thanks for your help |
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|