#!/bin/bash
# exitlab
#
# example of exit status
# check for non-existent file
# exit status will be 2
# create file and check it
# exit status will be 0
#
ls xyzzy.345 > /dev/null 2>&1
status='echo $?'
echo "status is $status"
# create the file and check again
# status will not be 0
touch xyzzy.345
ls xyzzy.345 > /dev/null 2>&1
status='echo $?'
echo "status is $status"
#remove the file
rm xyzzy.345
edx.org有一个实验室,这是脚本。当我运行它时,输出如下:Bash退出代码状态脚本错误
status is echo $?
status is echo $?
我想输出应该是0或2。我试图把括号一样status='(echo $?)
但导致status is echo $?
。然后,我尝试在单引号status=('echo $?')
之外放置括号,但是这给了我相同的输出status is echo $?
。
任何想法?
我会用'回声 “状态为” $'或'STT = $ ?;回声“状态是”$ stt' –