another simple unix scripting question! storing values in variables
how can I store the results of commands, for example if wc -l returns 6, how can I store the value into a variable in a unix script? thanks LQ!!
|
Try backquotes, e.g.
RESULT=`cat my_file.txt | wc -l` |
or use the $() construct:
Code:
RESULT=$(wc -l my_file.txt) Quote:
|
I do appreciate both of you for your kind response, and pwc is the winner this time!! :) pwc's method worked.
m0rg's method stores "cat file|wc -l" the command into the variable. The content of the variable becomes the "cat file|wc -l" not the result of the command. Also, Code:
result=$(cat file|wc -l) Code:
result=$(wc -l file) |
Quote:
Code:
RESULT=$(wc -l < file) |
All times are GMT -5. The time now is 09:48 AM. |