小编Vie*_*urs的帖子

测试字符串是否包含子字符串

我有代码

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)

现在输出为“真”。怎么会这样?如何解决问题?

string shell-script control-flow variable

48
推荐指数
4
解决办法
24万
查看次数

从 eval 返回值

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

bash exit eval exit-status

9
推荐指数
2
解决办法
2万
查看次数

一个命令中的gdb

当我program使用参数调试可执行文件时arg1 arg2gdb我执行以下序列

gdb
file ./program
run arg1 arg2
bt
quit
Run Code Online (Sandbox Code Playgroud)

如何从 shell 脚本中的一个命令行执行相同的操作?

gdb

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

bash ×1

control-flow ×1

eval ×1

exit ×1

exit-status ×1

gdb ×1

shell-script ×1

string ×1

variable ×1