Good day.
I am testing shell script over my own debian notebook
android-verify.sh: line 14: syntax error near unexpected token `then'
android-verify.sh: line 14: `if [[ ! -z $iopt ]] then { wd=$(pwd) basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname'
I am still new here. Please advised.
When attempt to include ;
In the following instruction
if [[ ! -z $iopt ]]**;** then { wd=$(pwd) basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname
scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname); su -c "cp $scriptname /usr/bin/monitor" root && echo "Congratulations! Script Installed, now run monitor Command" || echo$
fi
This bash terminal return the following messages
android-verify.sh: line 17: syntax error near unexpected token `fi'
android-verify.sh: line 17: `fi '
2
Answers
It appears as though you’re attempting to compose a shell script, but there are a few syntax errors in your code. In particular, you’re absent a semicolon and a line break before the
then
keyword, and there’s a mispositionedfi
at the conclusion. Here’s the rectified version of your code:Modifications applied:
#!/bin/bash
at the outset to specify the shell interpreter.iopt
to ensure the condition is satisfied in the illustration.if
clause structure by including a semicolon and a line break beforethen
.fi
at the conclusion.By incorporating these alterations, your script should function as intended. Just substitute
"certain_value"
with your real condition and confirm that you are executing this script within a bash shell.Here is the code rewritten with the changes to solve the problem and make it more readable:
then
which was correct.wd
variable, there was no semi-colon beforebase
so thewd
variable would have effectively only been set only for thebase
command and not any later commands.So in summary:
if
test and thethen
statementwd
andbase
echo$
toecho
Hope that helps.