ターミナルでこのコマンドを実行しようとしている間:
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" ];'
これはスクリプトのソースです:
#!/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
構文は私には正しいように見えます。また、同じ elif 構造を使用した、より単純なバージョンのスクリプトでも問題なく動作します。私は何を間違えましたか?(目的の関数が解析された後、スクリプトを終了する必要があります)