Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-14-2014, 04:37 PM   #1
LQ Newbie
Registered: Jul 2014
Posts: 1

Rep: Reputation: Disabled
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 :

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

please help. this is annoying!
Old 07-14-2014, 05:01 PM   #2
Didier Spaier
LQ Addict
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64- on Lenovo Thinkpad W520
Posts: 9,013

Rep: Reputation: Disabled
Hi and welcome to LQ.
\ is an escape character and as such should be escaped. Try this:
a=$(echo \\\\blabla\\bla\\bla | tr '\' '/')
echo $a
Old 07-15-2014, 03:30 AM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196Reputation: 1196
Or put the problem string in single quotes:
c@CW8:/tmp$ echo '\\blabla\bla\bla' | tr '\' '/'
tr: warning: an unescaped backslash at end of string is not portable
c@CW8:/tmp$ echo '\\blabla\bla\bla' | tr '\' '/' 2>/dev/null
Old 07-15-2014, 08:39 AM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
I am not sure I see the problem?

echo cd "${v//\\//}"
Not sure how the extra '/' at the start will play out for you.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] String Manipulation And Assigning Cobozco Linux - Newbie 10 06-07-2013 07:05 AM
BASH: Assigning a string containing pipes to a variable gearge Programming 5 11-27-2011 05:03 AM
Assigning custom string to std::string in C++ jh7777 Programming 4 10-13-2009 12:02 AM
Trouble assigning value to variable with fatsheep Programming 1 11-07-2006 07:44 PM
Assigning a string to a variable (not a pointer, not a array) JStew Programming 3 11-18-2002 08:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration