It's all about the answers!

Ask a question

Buildforge .bset - set variable as output of OS command


A B (1144) | asked Jun 10 '13, 8:15 p.m.

I am trying to define a buildforge command where I read a text file and want to assign the second line of the file to a variable.

According to Buildforge on-line help document this should be possible.  But i can't seem to get it working

e.g. my text file contains 2 lines

    1. Websphere Version
    2. ws7

I wish to assign text from second line to a variable, so I tried

.bset env "WS_VERSION_CAT[1] = `cat ${BF_ROOT}/wsVersion.txt`"

but the output I get is

409     6/10/13 7:59 PM        ENV     WS_VERSION_CAT[1]=Websphere Version:ws7

I was expecting the output to be just ws7

Also, how do I access this variable in next step?

Thank you

One answer



permanent link
Spencer Murata (2.3k115971) | answered Jun 11 '13, 8:08 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
 The 'cat' command will display the entire file.  So you would want to pipe it to sed to get a specific line number, so something like  `cat ${BF_ROOT}/wsVersion.txt | sed -n '2p'`.  The variable should be accessible then in the next step by using ${WS_VERSION_CAT[1]}

~Spencer

Comments
A B commented Jun 12 '13, 5:22 a.m. | edited Jun 12 '13, 5:23 a.m.

I will try this approach, but why does it not work the way I have as mentioned in the link - Buildforge on-line help document ?

By default, the system assigns the entire output of a command in backticks to the variable, but you can use range commands in brackets to select which lines from the command output you want to assign to your variable. The range numbers specify lines from the output using a 0-index  (the first line is numbered zero, the second 1, etc.). In the following example,

.set env SetupGroup "WindowsIPinfo[0,5-8]=`ipconfig`"

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.