Quote:
Originally Posted by theYinYeti
Two things:
- The answer is: surround your $(...) construct with double quotes.
- The return status stored in var is that of the echo command. You probably want to have the var= line just under the ls -al line; however, I'm not sure you'll get the return status of ls -al as this command is burried in a subshell...
Yves.
|
Thanks for replying me!
Well I have tested your solution but that's not seems to work...
Ok, here is the code
Code:
z="$(ls -al 2>&1)"
var=$?
echo $z
The output is :
Code:
total 12 drwxr-x--- 2 romain romain 4096 Aug 30 11:22 . drwx------ 10 romain romain 4096 Aug 30 11:22 .. -rwxr-x--- 1 romain romain 1303 Aug 30 11:22 test.sh
What I want is :
Code:
total 12
drwxr-x--- 2 romain romain 4096 Aug 30 11:22 .
drwx------ 10 romain romain 4096 Aug 30 11:22 ..
-rwxr-x--- 1 romain romain 1303 Aug 30 11:22 test.sh
As you can see, the output of ls does not add any carriage return or new line code..
I will check for the stderr stuff later.
Thanks