vdurieu
December 27, 2012, 8:40am
1
Hello
newbies question...
I just need a script able to launch a command when a condition is matched :
#!/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
./t2[5]: SIZ: not found
2
whats wrong ?
thanks for help
pamu
December 27, 2012, 8:45am
2
try sth like this..
SIZ=$(cat /nurp/control.lst|wc -l)
if [[ "$SIZ" -gt 0 ]]
then
echo 1
else
echo 2
fi
Jotne
December 27, 2012, 9:00am
3
A more simple version
SIZ=$(cat /nurp/control.lst|wc -l)
[[ "$SIZ" -gt 0 ]] && echo 1 || echo 2
Yoda
December 27, 2012, 12:43pm
4
No need to use cat and variable SIZ:
[[ $( wc -l < infile ) -gt 0 ]] && echo 1 || echo 2
RudiC
December 27, 2012, 1:56pm
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.
Yoda
December 27, 2012, 4:15pm
6
What RudiC mentioned is indeed an issue.
On top of that I see you are using single quote around the command:
'cat /nurp/control.lst|wc -l'
Replace that with:
SIZ=$( cat /nurp/control.lst|wc -l )
OR
SIZ=$( wc -l < /nurp/control.lst )