#!/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' –