我有代码
file="JetConst_reco_allconst_4j2t.png"
if [[ $file == *_gen_* ]];
then
echo "True"
else
echo "False"
fi
Run Code Online (Sandbox Code Playgroud)
我测试是否file
包含“gen”。输出为“假”。好的!
问题是当我用变量替换“gen”时testseq
:
file="JetConst_reco_allconst_4j2t.png"
testseq="gen"
if [[ $file == *_$testseq_* ]];
then
echo "True"
else
echo "False"
fi
Run Code Online (Sandbox Code Playgroud)
现在输出为“真”。怎么会这样?如何解决问题?
bash 手册指出:
eval [arg ...]
The args are read and concatenated together into a single com-
mand. This command is then read and executed by the shell, and
its exit status is returned as the value of eval. If there are
no args, or only null arguments, eval returns 0.
Run Code Online (Sandbox Code Playgroud)
我试试
eval `nonsense`
echo $?
Run Code Online (Sandbox Code Playgroud)
结果是0
。
而当我单独执行反引号命令时:
`nonsense`
echo $?
Run Code Online (Sandbox Code Playgroud)
结果是127
。
从什么是写在bash的手册我希望eval
以回报127
服用后引号时nonsense
作为参数。
如何获取参数的退出状态eval
?
当我program
使用参数调试可执行文件时arg1 arg2
,gdb
我执行以下序列
gdb
file ./program
run arg1 arg2
bt
quit
Run Code Online (Sandbox Code Playgroud)
如何从 shell 脚本中的一个命令行执行相同的操作?
bash ×1
control-flow ×1
eval ×1
exit ×1
exit-status ×1
gdb ×1
shell-script ×1
string ×1
variable ×1