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
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
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
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
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
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?
Do you encounter any problems with that code?
ASKER
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'
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much.
ASKER
is it possible to take '-' in linux date instead of '/' ?
ASKER
ok use $(date +"%d-%b-%Y %k:%M:%S") instead of $(date +"%d/%b/%Y %k:%M:%S") :-)
:-)
Thx for accepting!
wmp
Thx for accepting!
wmp
stat=error
elif [ $war -gt 0 ]; then
stat=warning
elif [ $rng -gt 0 ]; then
stat=wrong
else stat=OK
fi