LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (http://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   Accepting single backslash "\" as a user input. (http://www.linuxquestions.org/questions/linux-enterprise-47/accepting-single-backslash-%5C-as-a-user-input-772058/)

sundar_r05 11-28-2009 03:01 AM

Accepting single backslash "\" as a user input.
 
Dear friends,

how to do this in shell scripts. any solution for this or no solution.

My input will be : \svlipc32\masters\xxxx

my output should be : \svlipc32\masters\xxxx but its coming as
svlipc32mastersxxxx

presently iam giving i/p as \\svlipc32\\masters\\xxxx to get this
\svlipc32\masters\xxxx

Read Val
echo " Enter the input string \n"
echo $val
please help me in this.

Regards,
sundar

catkin 11-28-2009 03:28 AM

You could enter the value as '\svlipc32\masters\xxxx' (with the quotes)

ghostdog74 11-28-2009 04:06 AM

use -r

Code:

$ read -r s
\svlipc32\masters\xxxx
$ echo $s
\svlipc32\masters\xxxx
$read s #without -r
\svlipc32\masters\xxxx
$ echo $s
svlipc32mastersxxxx


catkin 11-28-2009 04:48 AM

Quote:

Originally Posted by ghostdog74 (Post 3772160)
use -r

Code:

$ read -r s

That's so much better than my suggestion :)

sundar_r05 02-02-2010 05:01 AM

Dear friends,

how to do this in shell scripts. any solution for this or no solution.

My input will be : \svlipc32\masters\xxxx ,\\svlipc32\\masters

my output should be : \svlipc32\masters\xxxx,\\svlipc32\\masters but its coming as svlipc32mastersxxxx and \svlipc32\masters

presently iam giving i/p as \\svlipc32\\masters\\xxxx to get this
\svlipc32\masters\xxxx

Read Val
echo " Enter the input string \n"
echo $val
please help me in this.

if I use -r read :

read -r val
echo $val

if i give this as input thats ok :- \svlipc32\masters\xxxx

but if i give this \\svlipc32\\masters as input iam getting \svlipc32\masters not as \\svlipc32\\masters.

Regards,
sundar

catkin 02-02-2010 05:23 AM

Works for me:
Code:

c:~$ read -r val
a\\b
c:~$ echo $val
a\\b


pixellany 02-02-2010 05:29 AM

This may be a bit late, but why do you need to have input that includes special characters like this? (Just seems to be asking for trouble.....)


All times are GMT -5. The time now is 05:45 AM.