Inserting Variable into sh Script Command [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-14 09:33:19

问题


#!/bin/sh -f

set proj_dir="OutputDir"
for projname in lib proj1 proj2
do
    mv ./scripts/$projname_BYTECODE ./$proj_dir/scripts/$projname
done

A very simple example of what is not working well for me. $projname_BYTECODE is being interpreted as a variable name but _BYTECODE is actually part of the folder name. Suggestions?


回答1:


Use ${X} instead of $X, so in your example ${projname}_BYTECODE should do the trick. Have a look at this question for more information: When do we need curly braces in variables using Bash?



来源:https://stackoverflow.com/questions/43416413/inserting-variable-into-sh-script-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!