#!/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有一个实验室,这是脚本。当我运行它时,输出如下:
status is echo $?
status is echo $?
我认为输出应该为0或2。我尝试将括号括起来,status='(echo $?)
但结果为status is echo $?
。然后,我尝试将括号放在单引号之外,status=( 'echo $?' )
但这给了我相同的输出status is echo $?
。
有任何想法吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句