【发布时间】:2014-10-29 11:41:09
【问题描述】:
在我正在编写的 shell 脚本中,我想从另一个文件中读取文件名,删除引号并为其添加文件扩展名。
tmp=$(awk '/output_onefile/ {getline;print}' $cmds_file)
tmp=$(echo "$tmp" | tr -d '"')
uh3dsr_file="${tmp}.sr_uh3d"
在$cmds_file 后面的文件中,“output_onefile”后面的行中有一个文件名。文件名在引号中,我在第二行中删除。至此,一切正常。 然后我只想将 .sr_uh3d 添加到文件名中。
当我运行这样的代码并假设文件名为“Blabla_123456”时,我最终得到以下结果:
echo "$uh3dsr_file"
.sr_uh3d23456
echo "Text $uh3dsr_file"
.sr_uh3dbla_123456
它将 .sr_uh3d 放在其余部分的前面并覆盖其余部分的开头。
谁能向我解释这种行为?清楚我想要做什么吗?
【问题讨论】:
-
您能否添加输入文件的示例?
-
也许这样做会更简单:`uh3dsr_file = echo $tmp".sr_uh3d"