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

user2725742
  • 398
  • 2
  • 12
  • 2
    ${projname}_BYTECODE? – C-Otto Apr 14 '17 at 17:37
  • You know, I "tried" that, but the syntax highlighting on gedit said it was still one variable so I did not actually try it. That does seem to have worked, though. You should answer the question. – user2725742 Apr 14 '17 at 17:41
  • 2
    As an aside; you've got some quoting bugs still present -- http://shellcheck.net/ will catch them. – Charles Duffy Apr 14 '17 at 17:53
  • 1
    `set` doesn't do what you think it does. – chepner Apr 14 '17 at 18:18
  • Yeah, I realized I put that in there accidentally when making this post. My script did not have that but copying&pasting was not working from my Linux VM at the time. So when I was typing it up, I mixed in some Tcl/Tk that I am unfortunately learning recently. – user2725742 Apr 15 '17 at 18:02

1 Answers1

4

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?

Community
  • 1
  • 1
C-Otto
  • 5,615
  • 3
  • 29
  • 62