shell script ssh command exit status

后端 未结 4 902
天命终不由人
天命终不由人 2020-12-31 01:34

In a loop in shell script, I am connecting to various servers and running some commands. For example

#!/bin/bash
FILENAME=$1
cat $FILENAME | while read HOST
         


        
4条回答
  •  旧巷少年郎
    2020-12-31 02:25

    You can assign the exit status to a variable as simple as doing:

    variable=$?
    

    Right after the command you are trying to inspect. Do not echo $? before or the new value of $? will be the exit code of echo (usually 0).

提交回复
热议问题