Home > OS >  Why in the shell script if statement will not perform
Why in the shell script if statement will not perform

Time:11-20

To echo the hello
If you write a script
Echo hello
If [$?==0]; Then
Echo 1
The else
Echo 0
Fi
After running the script, can be normal output hello and 1
But for the script
Su - root - c 'sshpass - p * password SSH -p 22222 * usrname @ * IP -o StrictHostKeyChecking=no' & gt;/dev/null 2 & gt; & 1
If [$?==0]; Then
Echo 1
The else
Echo 0
Fi
After running if statements are not performed, namely no output 1, 0, even deleted & gt;/dev/null 2 & gt; & 1 would be the output normal landing statement, the problem is where?

CodePudding user response:

I didn't read the other, as if [$?==0]; Then here==no. There is no space before and after the grammatical errors
As if [$? - eq 0]; Then a numerical comparison is better

CodePudding user response:

You are su gone, not in this user how to return a status code for you
  • Related