While trying to run this command in the terminal:
gerard@yoda ~$ Sources/Scripts/ultimate.sh -u -typecount -std /usr/bin py
Sources/Scripts/ultimate.sh: line 28: syntax error near unexpected token `elif'
Sources/Scripts/ultimate.sh: line 28: `elif [ $1 = "-h" ];'
this is the source of the script:
#!/bin/bash
## $1 = Mode(u/h) ; $2 = Command(?) ; $3+ = Params
if [ $1 = "-u" ];
if [ $2 = "-typecount" ];
then
if [ $3 = "-std" ];
then
find $4 -maxdepth 1 -iname *.$5 | wc -l
elif [ $3 = "-ext" ];
then
find $5 -maxdepth $4 -iname *.$6 | wc -l
else
echo 'use option -std for single-dir'
echo 'or option -def for recusive with custom depth'
echo 'filetype should be defined type instead of .type'
fi
elif [ $2 = "-prep" ];
then
sed -i 's/^/$3/' $4
elif [ $2 = "-app" ];
then
sed -i 's/$/$3/' $4
else
echo 'No command specified/Command not found'
fi
elif [ $1 = "-h" ];
then
if [ $2 = "-typecount" ];
then
echo 'for -std: [location] [type]'
echo 'for -ext: [depth] [location] [type]'
elif [ $2 = "-prep" ];
then
echo '[text] [file]'
elif [$2 = "-app" ];
then
echo '[text] [file]'
else
echo 'No command specified/Command not found'
else
echo 'No mode specified/Wrong mode'
fi
The syntax appears correct to me, and a simpler version of the script, with same elif construction works fine. What did I do wrong? (the script needs to quit after the desired function is parsed)
At the top you don’t have a
thenkeyword after the firstif.You’re also missing an
finear the bottom: