LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-14-2014, 04:37 PM   #1
kobi666
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 :
/blablablabla

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-14.2 on Lenovo Thinkpad W520
Posts: 7,444

Rep: Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404Reputation: 2404
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
 
Old 07-15-2014, 03:30 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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
 
Old 07-15-2014, 08:39 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,494

Rep: Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867Reputation: 2867
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.
 
  


Reply


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


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

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