Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
06-11-2003, 01:59 PM
|
#1
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Rep:
|
Using echo to output a string to a file with forward slashs
I'm trying to issue this command:
echo "\jsmith, "|/usr/bin/vacation jsmith"" >> /users/jsmith/.forward
But when I do, it doesnt output the string to the .forward file. Does anyone have a clue as to why this is happening?
|
|
|
|
06-11-2003, 02:22 PM
|
#2
|
|
Senior Member
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
|
What, exactly, do you want in the file? Your quoting isn't correct, and it's unclear to me what you want in the file. If you want this:
Code:
\jsmith, "|/usr/bin/vacation jsmith"
in your file, then you need to learn about escaping characters. There are three types of escapes, ", ', and \. They each do things a little differently and it's very important to use them in the correct manner. For this application, you need to use the ' escape:
Code:
echo '\jsmith, "|/usr/bin/vacation jsmith"' >> file
I'm not trying to be rude, just stating that escaping characters from the shell is something that causes a lot of grief when it doesn't need to. . .
|
|
|
|
06-11-2003, 02:41 PM
|
#3
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
What I'm trying to do, is interpret this line:
echo '\$username, "|/usr/bin/vacation $username"' >> .forward
to:
--------------------------------------------------
\jsmith, "|/usr/bin/vacation jsmith"
--------------------------------------------------
within a script I am writing. The output should go be exactly what is shown.
Thanks alot
|
|
|
|
06-11-2003, 04:55 PM
|
#4
|
|
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263
Rep:
|
"\\$username, \"|/usr/bin/vacation $username\"" i think, basically in " quotes everything is interpreted by the shell, to put a shell-character in literally prefix it with a \ eg \ is produced by \\ " is produced by \" etc
|
|
|
|
06-12-2003, 01:53 PM
|
#5
|
|
Senior Member
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
|
Use the command I gave above.
|
|
|
|
06-12-2003, 02:12 PM
|
#6
|
|
Moderator
Registered: May 2001
Posts: 24,786
|
Btw, if you want to "resolve" username using the env vars, it's $USERNAME, or $LOGNAME, AFAIK.
|
|
|
|
06-20-2003, 07:02 AM
|
#7
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
In my script, when its time for this line to be interpreted:
echo '\$username, "|/usr/bin/vacation $username"' >> .forward
I want the line in the .forward file to look like this:
\jsmith, "|/usr/bin/vacation jsmith"
Right now, its only outputting this:
\$username, "|/usr/bin/vacation $username
|
|
|
|
06-20-2003, 11:33 AM
|
#8
|
|
Senior Member
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
|
Use this:
echo '\'$USER', "|/usr/bin/vacation ' $USER'"'
Whatever is processing the forms is interpreting the above text in such a way that it removes the backslash.
Should be:
echo ' \ ' $USER', "|/usr/bin/vacation ' $USER'"'
without the space between the \ and the single quotes.
Last edited by moses; 06-20-2003 at 11:39 AM.
|
|
|
|
06-20-2003, 12:32 PM
|
#9
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
That almost works to perfection, but what I get from that is this:
\ ckoniecny, "|/usr/bin/vacation ckoniecny"
instead of this:
\ckoniecny, "|/usr/bin/vacation ckoniecny"
Notice the that there is no space on the one that I would like to have output to a file.
Thanks
|
|
|
|
06-20-2003, 01:14 PM
|
#10
|
|
Member
Registered: May 2003
Location: Nashville TN, USA
Distribution: Debian (I'm unstable)
Posts: 117
Rep:
|
there is also a space between the single quote and the $USER that you'll need to remove
|
|
|
|
06-20-2003, 01:19 PM
|
#11
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
I did, this is the command I'm using as of right now...
echo '\' $username', "|/usr/bin/vacation' $username'"' >> .forward
|
|
|
|
06-20-2003, 01:36 PM
|
#12
|
|
Member
Registered: May 2003
Location: Nashville TN, USA
Distribution: Debian (I'm unstable)
Posts: 117
Rep:
|
yeah, it still looks like there is a space between the second single quote (after the backslacsh) and the $. maybe its just the way the forums are formatted
|
|
|
|
06-20-2003, 02:28 PM
|
#13
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
I copied and pasted that command moses gave me and the space was there even after I removed it, any ideas?
|
|
|
|
06-20-2003, 03:22 PM
|
#14
|
|
Senior Member
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152
Rep:
|
The only single quote that should have a space near it is the one that comes after vacation. echo takes everything literally unless it's escaped out (by single or double quotes or backslashes). echo does not strip whitespace, you need to do that yourself:
echo '\'$USER', "|/usr/bin/vacation '$USER'"'
Last edited by moses; 06-20-2003 at 03:24 PM.
|
|
|
|
06-21-2003, 09:58 AM
|
#15
|
|
Member
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289
Original Poster
Rep:
|
This is the command am using right now:
echo '\' $username', "|/usr/bin/vacation' $username'"' >> .forward
And this is the output it gives me (notice the space after the backslash, it shouldnt be there):
\ jsmith, "|/usr/bin/vacation jsmith"
It should be:
\jsmith, "|/usr/bin/vacation jsmith"
How do I fix that extra space after that backslash?
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:50 PM.
|
|
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
|
|