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? |
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" Code:
echo '\jsmith, "|/usr/bin/vacation jsmith"' >> file |
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 |
"\\$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
|
Use the command I gave above.
|
Btw, if you want to "resolve" username using the env vars, it's $USERNAME, or $LOGNAME, AFAIK.
|
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 |
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. |
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 |
there is also a space between the single quote and the $USER that you'll need to remove
|
I did, this is the command I'm using as of right now...
echo '\' $username', "|/usr/bin/vacation' $username'"' >> .forward |
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
|
I copied and pasted that command moses gave me and the space was there even after I removed it, any ideas?
|
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'"' |
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? |
All times are GMT -5. The time now is 09:19 PM. |