LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-17-2005, 04:55 AM   #1
esasse
LQ Newbie
 
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17

Rep: Reputation: 0
Question backslash input in script


Hello,

I'm trying to write a script to install a software and the user have to input a Windows UNC path, like \\server\share and I'm using:

echo -n "Path:"
read caminho

Then the user types "\\server\share", but when I try to echo it to a file I got "\servershare".

How can I tell the script to ignore and don't interpret the backslashs as scape characters?

Thanks!
 
Old 02-17-2005, 05:30 AM   #2
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,938

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
Use another backslash to escape "\", like this:
\\\\server\\share
 
Old 02-17-2005, 05:35 AM   #3
esasse
LQ Newbie
 
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks, I know this way.

But I hope there is another way so that I don't need to instruct my users to input doubled slashs.
Is there a way?
 
Old 02-17-2005, 06:06 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,938

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
Then do a "read -r caminho" to let "\" be interpreted literally.
 
Old 02-17-2005, 06:12 AM   #5
esasse
LQ Newbie
 
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks bathory! It working now!

Just one more doubt how can I check if the user type a backslash at the end, like:

\\server\share

or

\\server\share\

Because I need to concatenate a filename after the path.
 
Old 02-17-2005, 06:37 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
(Side-note: with single quotes '\\server', \ are not interpreted by the shell.)

Let's say your server name is $MyServer, and is equal to either '\\server\share' or '\\server\share\', and you want to append the value of RelativePath, that looks like 'relative\path' or '\relative\path'. Do it this way in bash:
Code:
AbsolutePath="${MyServer%/}/${RelativePath#/}"
Yves.
 
Old 02-17-2005, 06:55 AM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,938

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
As a quick solution add:
Code:
caminho="${caminho/%\\/}"
to remove the trailing "\" if exists and concatenate "\filename"
Take a look at this guide to help you with bash scripting.

Regards
 
  


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
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 03:46 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
script input question linuxnube Linux - Software 0 03-17-2004 08:38 AM
script and password input Rex_chaos Linux - General 1 07-22-2003 03:04 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration