我正在编写一个BASH脚本,我正在使用 bash 命令。以下哪一项是正确的(或两者都不正确)?
bash $pbs_dir/${module_name}.${target_ID}.${instance_ID}.pbs
或
bash \$pbs_dir/\${module_name}.\${target_ID}.\${instance_ID}.pbs
答案 0 :(得分:3)
\$
将扩展为文字$
,因此存在很大差异:
$ a="hello"
$ echo $a
hello
$ echo \$a
$a
另请注意,您几乎总是想要引用参数扩展,以避免word splitting和pathname expansion:
echo "$a"
所以你想要使用以下内容:
bash "$pbs_dir/${module_name}.${target_ID}.${instance_ID}.pbs"