Results 1 to 3 of 3
I can print a specific line of a file with:
$ sed -n '20p' myFile
How can I store it in a variable (in a shell script)?
(I wasn't successful ...
- 09-10-2010 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 12
how can I assign a variable to a linux command
I can print a specific line of a file with:
$ sed -n '20p' myFile
How can I store it in a variable (in a shell script)?
(I wasn't successful with "myVar=sed -n '20p' myFile" for example)
- 09-11-2010 #2Just Joined!
- Join Date
- Sep 2007
- Posts
- 25
Will set it the first time, but you need to do that on each iteration.Code:myVar=`sed -n '20p' myFile`
That's old school. The newer way is
Code:myVar=$(sed -n '20p' myFile)
- 09-11-2010 #3
Backward quote (`): Commands within backward quotes are executed and their output substituted into that location.
Output:Code:foo=`echo bar` echo $foo
bar


Reply With Quote