LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   equivalent of read -r (https://www.linuxquestions.org/questions/linux-newbie-8/equivalent-of-read-r-853852/)

balakodoth 01-03-2011 02:58 AM

equivalent of read -r
 
what is the equivalent of read -r (solaris command ) in Linux ?

read utility in solaris will read a single line from standard input and -r option is used not to treat backslash (\) as an escape character .

grail 01-03-2011 03:18 AM

All the same as far as I know??
Code:

# help read | grep '\-r'
-r                do not allow backslashes to escape any characters


balakodoth 01-03-2011 03:26 AM

thanks grail ,

I like to know whether there is any similar command in linux which does the same functionality as read -r in solaris .

balakodoth 01-03-2011 03:58 AM

echo "A B C" | read x y z
echo $x $y $z

gives A B C in solaris but when i give same in Linux it gives blank.

does anyone know how to acheive this in Linux ? ( reading from standard input )

crts 01-03-2011 04:09 AM

Quote:

Originally Posted by balakodoth (Post 4211224)
echo "A B C" | read x y z
echo $x $y $z

gives A B C in solaris but when i give same in Linux it gives blank.

does anyone know how to acheive this in Linux ? ( reading from standard input )

The problem is that the pipe is being executed in a subshell. 'x', 'y' and 'z' get "A", "B" and "C" assigned. However, after the commands are executed the subshell also exits and the assigned values are lost.

If you want to keep them you can do something like this:
Code:

$ read x y z < <(echo "D E F")
$ echo $x
D
$ echo $y
E
$ echo $z
F
$ echo $x $y $z
D E F
$



All times are GMT -5. The time now is 09:07 AM.