Bash 使用$(…)获取子命令的错误代码
在此代码中:Bash 使用$(…)获取子命令的错误代码,bash,exit-code,Bash,Exit Code,在此代码中: echo hello>hello.txt 阅读X使用过程替换而不是命令替换+此处字符串: read X < <(grep 'hello' hello.txt) 只是: 对于要使用读取进行分词的一般情况,请使用临时变量: tmp=$(grep hello hello.txt) echo $? IFS=' ' read -r name something somethingelse <<<"$tmp" tmp=$(grep hell
echo hello>hello.txt
阅读X使用过程替换
而不是命令替换+此处字符串
:
read X < <(grep 'hello' hello.txt)
只是:
对于要使用读取进行分词的一般情况,请使用临时变量:
tmp=$(grep hello hello.txt)
echo $?
IFS=' ' read -r name something somethingelse <<<"$tmp"
tmp=$(grep hello.txt)
回声$?
如果s=''read-r name something为什么read X My mys take,这是一个愚蠢的例子。基本上我想做一些类似command$(grep hello.txt)
的事情,然后检查grep
是否成功。使用一个临时变量<代码>tmp=$(grep hello.txt);grep_exit_status=$?;命令“$tmp”
。谢谢您的回答。我会的。但我想知道是否有某种形式的“返回代码堆栈”来获取旧命令的代码。你们太快了!
X=$(grep hello hello.txt)
echo $?
tmp=$(grep hello hello.txt)
echo $?
IFS=' ' read -r name something somethingelse <<<"$tmp"