Reputation: 11
Getting syntax error near unexpected token `fi' while executing below code. below is the output:-
: command not founde 2:
: command not founde 7:
run_billing.sh: line 22: syntax error near unexpected token `fi'
'un_billing.sh: line 22: `fi
The script is:
#!/bin/sh
#
# main
#
NARGS=$#
if [ $NARGS -lt 2 ]
then
echo "$PRG_NAME: error: incorrect number of arguments ($NARGS)";
echo "Usage: $PRG_NAME [Time]";
echo "Time format - pin_virtual_time format. e.g:- 062000002015.00";
echo "Example: sh run_billing.sh 062000002015.00";
exit 1
fi
if [ $NARGS -eq 2 ]
then
echo "Run Billing script - pin_bill_day";
pin_virtual_time -m2 $1;
pin_bill_day;
fi
Upvotes: 0
Views: 4176
Reputation: 882146
Your line endings are screwed up, each line is terminated by a CR/LF rather than just an LF.
If you do something like od -c run_billing.sh
, you'll see them there as \r
characters as per my test script (the ^M
characters are CR):
if [[ 1 -eq 1 ]]^M
then^M
echo x is 1^M
fi^M
^M
0000000 i f [ [ 1 - e q 1 ] ]
0000020 \r \n t h e n \r \n \t e c h o x
0000040 i s 1 \r \n f i \r \n \r \n
0000054
And, when that file is run, we see a similar issue.
That's why you're getting the weird error output, because the CR is moving the cursor to the start of the line before continuing the message, overwriting some of what it's already output.
For example, lines 2 and 7 of your script (the supposedly blank lines) contain a single CR character which is interpreted as a command which doesn't exist. So, for line 2, you see (superimposed):
run_billing.sh: line 2:<CR>
: command not found
=========================== giving:
: command not founde 2:
exactly what you see.
You need to modify the file to remove those CR characters, a couple of ways of doing that are given in this excellent answer.
Upvotes: 2