0

I am trying to run a RTC 4.x command to add components to a workspace. The list of components have spaces in the names so they need to be surrounded by quotes. I am storing this list in a simple string variable:

COMPONENTS="\"TestComp\" \"Common Component\""

When I just echo out COMPONENTS it displays correctly, but when I use it in a scm command odd things happen to the quotes. I am running this in Jenkins so I can get some additional output, but the same thing happens when I run it on the command line so this is not a Jenkins issue.

From the console log:

+ COMPONENTS='"TestComp" "Common Component"'
+ echo '"TestComp"' '"Common' 'Component"'
"TestComp" "Common Component"

The command is trying to run the following:

+ scm workspace add-components TEST_Workspace -s Test_Stream '"TestComp"' '"Common' 'Component"'

Which produces:

Problem running 'workspace add-components':
Unmatched component ""Common".
JamesE
  • 3,833
  • 9
  • 44
  • 82

1 Answers1

2

Typically, you need to use an array to store items that may themselves contain whitespace:

components=("TestComp" "Common Component")
scm workspace add-components TEST_Workspace -s Test_Stream "${components[@]}"

Quoting an array expansion indexed with @ produces a sequence of words, one per element of the array, rather than a single word.

chepner
  • 497,756
  • 71
  • 530
  • 681
  • Good thought, but I had tried the array route as well. This produces similar results depending on how I play with the quotes. For example: `components=("TestComp" "Common Component")` results in a `com.ibm.team.scm.common.ComponentNotInWorkspaceException: Component 'TestComp' is not in workspace` error. This `components=("TestComp" "'Common Component'")` produces `Unmatched component "'Common Component'".` – JamesE Apr 25 '14 at 19:58
  • 1
    How would you call `scm` if you were specifying the components manually, without trying to store them in a variable? The first error you show (for the code that I claim should work) looks more like a problem with the setup than with the `bash` command. – chepner Apr 25 '14 at 20:12
  • @JimG Did you use double-quotes around the array reference (as in `"${components[@]}"`)? – Gordon Davisson Apr 25 '14 at 20:15
  • @GordonDavisson yes, I put double quotes around the array reference. @chepner If I were calling the command manually it would be: `scm workspace add-components TEST_Workspace -s Test_Stream TestComp "Common Component"` or it could also be `scm workspace add-components TEST_Workspace -s Test_Stream "TestComp" "Common Component"` – JamesE Apr 25 '14 at 20:19
  • And that works? There should be no difference between my code and that. – chepner Apr 25 '14 at 20:24
  • OK, I started from scratch with a completely new workspace and @chepner your original solution does work. RTC must have been caching something. Thanks for the help - I appreciate it! – JamesE Apr 25 '14 at 20:36