我有这个 if 语句:
if $type = 1 then
date +%s | md5 | base 64 | head -c $length >> $name.txt
elseif $type = 2 then
date +%s | shasum | base 64 | head -c $length >> $name.txt
elseif $type = 3 then
openssl rand -base64 $length >> $name.txt
fi
我一直收到错误:
./password: line 32: syntax error near unexpected token `fi'
./password: line 32: `fi'
可能我做了一些愚蠢的事情但我不知道我错在哪里!
提前致谢!!
答案1
始终组织你的代码,并在执行整数条件时使用 -eq
if [ $type -eq 1 ]
then
date +%s | md5 | base 64 | head -c $length >> $name.txt
elif [ $type -eq 2 ]
then
date +%s | shasum | base 64 | head -c $length >> $name.txt
elif [ $type -eq 3 ]
then
openssl rand -base64 $length >> $name.txt
fi