Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Korn shell help

Dec 3, 2010 8:07AM PST

Hello, I am having problems seeing what I am doing wrong here. This is a ksh file..it contains a DB2 database command but I will display the output. The problem I have is when I try to use the local_value variable..it doesnt show up:

db_cmd="select count(*) from table1"
db2 -x "${db_cmd}" 1>${local_value}
print "value = ${local_value}"

The result of running db_cmd without the output to local_value is:

1
-------------
83

1 record(s) selected.

The local_value is to capture the "83", which is what outputs to my screen at this point. So..the output looks like:

83

But when it prints the value it looks like:

value =

I have also added an " | awk '{print $1}' " to the command line it removes all the spaces from the beginning of 83 but that doesnt seem to help the print.

Any ideas?

Discussion is locked

- Collapse -
Looks like more work is needed.
Dec 3, 2010 8:27AM PST

The output is not "83" but
"1
-------------
83

1 record(s) selected."

It appears you'll have to parse the output and pick out the third line.
Bob

- Collapse -
it outputs to screen correctly
Dec 3, 2010 9:35AM PST

Yes, the output is the entire 5 lines but I am able to get it to output only the line with the "83" to screen..but nothing shows up at all in the print statement.

- Collapse -
Wish I was there. But try this.
Dec 5, 2010 9:24AM PST

Redirect the output to a file then parse that file.
Bob