如果条件,则Bash语法错误

时间:2017-10-31 10:27:52

标签: bash

我试图弄清楚为什么这个简单的代码会产生语法错误。有什么建议吗?

./g.sh: line 4: syntax error in conditional expression: unexpected token `;'
./g.sh: line 4: syntax error near `;'
./g.sh: line 4: `    if [[ "$y" == "rsa" ]]; then'

以下是代码:

for x in *; do
  for y in rsa ed25519; do
    yb=''
    if [[ "$y" == "rsa" ]]; then
      yb=' -b 4096'
    fi
    echo "x: ${x} y: ${y} yb: ${yb}"
  done
done

这只是用于为许多机器自动生成rsa / ed25519密钥的测试代码。

一些额外的信息:

  • Ubuntu Server 17.10
  • GNU bash 4.4.12

1 个答案:

答案 0 :(得分:0)

  
    

nano 2.sh

  
for x in *; do
 for y in rsa ed25519; do
 yb=''
  if [[ "$y" == "rsa" ]]; then
   yb=' -b 4096'
  fi
 echo "x: ${x} y: ${y} yb: ${yb}"
 done
done}
  
    

chmod + x 2.sh

         

/2.sh

  
x: 1.sh y: rsa yb:  -b 4096
x: 1.sh y: ed25519 yb: 
x: 2.sh y: rsa yb:  -b 4096
x: 2.sh y: ed25519 yb: 
x: abc.txt y: rsa yb:  -b 4096
x: abc.txt y: ed25519 yb: 
x: dene.csv y: rsa yb:  -b 4096
x: dene.csv y: ed25519 yb: 
x: deneme y: rsa yb:  -b 4096
x: deneme y: ed25519 yb: 
x: dene.sh y: rsa yb:  -b 4096
x: dene.sh y: ed25519 yb: 
x: dene.txt y: rsa yb:  -b 4096
x: dene.txt y: ed25519 yb: 
x: Desktop y: rsa yb:  -b 4096
x: Desktop y: ed25519 yb: 
x: Downloads y: rsa yb:  -b 4096
x: Downloads y: ed25519 yb: 

GNU bash,版本4.4.12

Parrot 4.11.6-1parrot6 enter code here