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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-17-2005, 05:55 AM
|
#1
|
LQ Newbie
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17
Rep:
|
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!
|
|
|
02-17-2005, 06:30 AM
|
#2
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
|
Use another backslash to escape "\", like this:
\\\\server\\share
|
|
|
02-17-2005, 06:35 AM
|
#3
|
LQ Newbie
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17
Original Poster
Rep:
|
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?
|
|
|
02-17-2005, 07:06 AM
|
#4
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
|
Then do a "read -r caminho" to let "\" be interpreted literally.
|
|
|
02-17-2005, 07:12 AM
|
#5
|
LQ Newbie
Registered: Nov 2004
Location: Americana, SP - Brazil
Distribution: Fedora
Posts: 17
Original Poster
Rep:
|
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.
|
|
|
02-17-2005, 07:37 AM
|
#6
|
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897
Rep:
|
(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.
|
|
|
02-17-2005, 07:55 AM
|
#7
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,215
|
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
|
|
|
All times are GMT -5. The time now is 01:36 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|