Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Variable into sh Script Command [duplicate]

Tags:

#!/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?

like image 376
user2725742 Avatar asked Apr 14 '17 17:04

user2725742


1 Answers

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?

like image 142
C-Otto Avatar answered Sep 23 '22 10:09

C-Otto