LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   assigning a string with '/' from $1 to a variable (https://www.linuxquestions.org/questions/linux-newbie-8/assigning-a-string-with-from-%241-to-a-variable-4175511096/)

kobi666 07-14-2014 04:37 PM

assigning a string with '/' from $1 to a variable
 
hi all

i tried this in numerous ways,
but i just can't seem to make this work.

i want to make an alias that takes a windows network path (\\blabla\bla\bla)
and reverts the slashes (\\blabla\bla\bla > //blabla/bla/bla)
then cd's into the output.

if i do an #echo \\blabla\bla\bla | tr '\' '/'
it works fine, but if i try to assign this to a variable, then
it writes it with one slash and without the others in the argument , like so :
/blablablabla

even if the variable input comes form the #echo command.

please help. this is annoying!

Didier Spaier 07-14-2014 05:01 PM

Hi and welcome to LQ.
\ is an escape character and as such should be escaped. Try this:
Code:

a=$(echo \\\\blabla\\bla\\bla | tr '\' '/')
echo $a


catkin 07-15-2014 03:30 AM

Or put the problem string in single quotes:
Code:

c@CW8:/tmp$ echo '\\blabla\bla\bla' | tr '\' '/'
tr: warning: an unescaped backslash at end of string is not portable
//blabla/bla/bla
c@CW8:/tmp$ echo '\\blabla\bla\bla' | tr '\' '/' 2>/dev/null
//blabla/bla/bla


grail 07-15-2014 08:39 AM

I am not sure I see the problem?
Code:

v='\\blabla\bla\bla'

echo cd "${v//\\//}"

Not sure how the extra '/' at the start will play out for you.


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