BASH脚本:何时包含反斜杠符号

时间:2016-06-15 21:20:29

标签: bash symbols backslash quoting

我正在编写一个BASH脚本,我正在使用 bash 命令。以下哪一项是正确的(或两者都不正确)?

bash $pbs_dir/${module_name}.${target_ID}.${instance_ID}.pbs

bash \$pbs_dir/\${module_name}.\${target_ID}.\${instance_ID}.pbs

1 个答案:

答案 0 :(得分:3)

\$将扩展为文字$,因此存在很大差异:

$ a="hello"
$ echo $a
hello
$ echo \$a
$a

另请注意,您几乎总是想要引用参数扩展,以避免word splittingpathname expansion

echo "$a"

所以你想要使用以下内容:

bash "$pbs_dir/${module_name}.${target_ID}.${instance_ID}.pbs"