![]() |
Executing a command in Shell Script
Hi,
I have a command in a variable. How to execute that command, Something like, a="date|awk '{print \$1\"\n\"\$2}'" now i need to execute the command stored in $a please help me |
Hello,
you may try something like: Code:
a="ls -l" |
Hi,
thanks for ur reply. i already know that, we can execute command like, echo `$a` but i try to execute my command in the same way, i.e. a="date|awk '{print \$1\"\n\"\$2}'" echo `$a` i got this error: -bash: date|awk: command not found |
some simple debugging may help you to get through
first, echo out the value of a, and see if the value is assigned and constructed properly. If its not constructed properly, no matter how you do, you will always get error... |
a=$(date|awk '{print \$1\"\n\"\$2}') ?
|
Doing a single command like:
a=date $a would work as you are expecting. Maybe you want to create a function instead of a variable: Code:
b() |
... and you don't need awk:
Code:
% dt="$(date +%a\\n%b)" |
Hi jschiwal,
thanx for ur reply that's what, what i was looking for now my way is clear |
| All times are GMT -5. The time now is 10:13 AM. |