Reputation: 397
Here is my scenario:
well i use csh
1)
$ ls -l /corefiles/ | grep "root"
-rw-r----- 1 root root 0 Sep 22 2014 core.3.4.
-rwxr-x--- 1 root root 92 Sep 22 2014 ss.sh
2)
$ set textInfo=`ls -l /corefiles/ | grep "root"`
$ echo $textInfo
-rw-r----- 1 root root 0 Sep 22 2014 core.3.4. -rwxr-x--- 1 root root 92 Sep 22 2014 ss.sh
But I need echo $textInfo
to give output like 1).
How can I achieve this? I do not want to redirect the content into a file. I need to store console output in a variable but with the same format as present in the console.
I need a variable which has content as below:
$ echo $textInfo
-rw-r----- 1 root root 0 Sep 22 2014 core.3.4.
-rwxr-x--- 1 root root 92 Sep 22 2014 ss.sh
Upvotes: 0
Views: 529
Reputation: 652
try this:
textInfo=$(ls -l /corefiles/ | grep "root")
then
echo "$textInfo"
Upvotes: 0
Reputation: 16718
Use echo "$textInfo"
instead of echo $textInfo
. Otherwise the variable is expanded as part of the command line instead of as a string, so the newlines aren't preserved.
Upvotes: 4