Write output or command to variable (shell)
Hi i want to write an output of a command to a variable, How do I do this is shell script ?
Many Thanks. |
I presume you mean in a bash command...? Something like this...?
Code:
fukawi2@fukawi-desktop:~$ CMDOUT=`uname -r` ` not ' or " |
Yup that worked thanks.
|
or use set:
Code:
$ date |
If you were asking about doing it within a bash script, run info bash and look at the descriptions of the $(expression) and ${expression} constructions.
|
its ment to read output "of"
|
Quote:
You learn something all the time. |
Posted by: Kernel geek
Hi i want to write an output of a command to a variable, How do I do this is shell script ? Hey, let's try this who.out=`who | wc -l` echo $who.out # who.out is your output variable (or) LS=`ls -l` # place the value of ls-l into variable LS echo $LS # and LS is your output of variable |
or lots of vars:
for var in $(ls /); do echo $var done no fan mail please :)) |
i can't help myself...
create a little script: #!/bin/sh lsmsg=hello for var in $(ls /); do echo $var-$lsmsg done make an alias: alias ls=scriptname now, type ls nice? alas the many ways to personalize your pc. cheers sp ps: want to get rid of the new and improved ls command? unalais ls |
All times are GMT -5. The time now is 04:57 AM. |