|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script with variable and condition
Hello newbies question... I just need a script able to launch a command when a condition is matched : Code:
#!/bin/ksh SIZ = 'cat /nurp/control.lst|wc -l' if test "$SIZ" -gt 0 then echo 1 else echo 2 fi but I receive errors messages Code:
./t2[5]: SIZ: not found 2 whats wrong ? thanks for help Last edited by Franklin52; 12-28-2012 at 08:09 AM.. Reason: Please use code tags for data end code samples |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
try sth like this.. Code:
SIZ=$(cat /nurp/control.lst|wc -l) if [[ "$SIZ" -gt 0 ]] then echo 1 else echo 2 fi |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
A more simple version Code:
SIZ=$(cat /nurp/control.lst|wc -l) [[ "$SIZ" -gt 0 ]] && echo 1 || echo 2 |
|
#4
|
||||
|
||||
|
No need to use cat and variable SIZ: Code:
[[ $( wc -l < infile ) -gt 0 ]] && echo 1 || echo 2 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Pls use code tags as advised.
All proposals above are fine and work, but I think your ./t2[5]: SIZ: not found error comes from the two spaces around the equals-sign when defining SIZ. Remove them, test, and come back with result. |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
What RudiC mentioned is indeed an issue. On top of that I see you are using single quote around the command: Code:
'cat /nurp/control.lst|wc -l' Replace that with: Code:
SIZ=$( cat /nurp/control.lst|wc -l ) OR Code:
SIZ=$( wc -l < /nurp/control.lst ) |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare the two variable with if condition | aroragaurav.84 | Shell Programming and Scripting | 5 | 06-28-2012 10:38 AM |
| Problem using shell variable in awk if condition | vishwas.s | Shell Programming and Scripting | 4 | 05-30-2012 05:19 PM |
| Bash: if condition as variable | curlee2002 | Shell Programming and Scripting | 2 | 02-20-2010 01:24 PM |
| csh if loop variable condition check peroblem | vasanth.vadalur | Shell Programming and Scripting | 0 | 11-06-2009 07:43 AM |
| if condition for variable existing in file | eltinator | Shell Programming and Scripting | 3 | 02-15-2009 11:35 PM |
|
|