Question

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".
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top