Link to home
Start Free TrialLog in
Avatar of Jasmin shahrzad
Jasmin shahrzad

asked on

bash file

in bash file i have a if statement

if [err -gt 0] then  # if err greather that 0
 stat=error
elsif [war -gt 0] then
 stat=warning
elseif [rng -gt 0] then
 stat=wrong
else stat=OK
fi

syntax error near unexpected token `else'
'else stat=OK'

what is wrong her
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

if [ $err -gt 0 ]; then  # if err greater thatn 0
 stat=error
elif [ $war -gt 0 ]; then
 stat=warning
elif [ $rng -gt 0 ]; then
 stat=wrong
else stat=OK
fi
Explanation:

1) Put a space after [ and before ]
2) Variables must start with $
3) Put a semicolon or a linefeed before "then"
4) Use "elif". There is no "elsif" in bash

Here is the guide:
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
Avatar of Jasmin shahrzad
Jasmin shahrzad

ASKER

ok if i want a 2 statement after then should use ;
i mean :
if [ $err -gt 0 ]; then  # if err greater thatn 0
 stat=error;
sed "s/oldin_time/$start/g; s/oldout_time/$stop/g; s/oldjob_name/$new/g; s/oldjob_nr/1/g; s/oldrec_nr/$rek/g; s/oldstatus/$stat/g" insert.sql > ${new}_insert.sql

elif[...]
..
fi
Looks good. I think it should work.
Do you encounter any problems with that code?
yes i find what the problem is. but i don't no. how can i solve it.
problem is one of this variable is date from linux with code
 start=$(date +"%d/%b/%Y %k:%M:%S")
and i can't make a sed on file and change it imean
sed "s/oldin_time/$start/g; s/oldout_time/$stop/g"  insert.sql > test.sql
error is: char 17: unknown option to `s'
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you very much.
is it possible to take '-' in linux date instead of '/'  ?
ok use $(date +"%d-%b-%Y %k:%M:%S") instead of  $(date +"%d/%b/%Y %k:%M:%S")   :-)
:-)

Thx for accepting!

wmp