Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
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.
but of course that won't work, because it'll try to mail a message with the subject 'Error' to the user 'from', 'daily_backups', and 'root'. So the question is how to get quotes around the subject.
The obvious is to escape a quote or double-quote. But that gives me:
MAIL="/bin/mailx -s \'Error from $(basename $0)\' root"
which the shell expands to
+ /bin/mailx -s '\'\''Error' from 'daily_file_backup\'\''' root
which doesn't work, or
MAIL="/bin/mailx -s \"Error from $(basename $0)\" root"
There are two secrets to quoting:
1. The "hard quote" (') protects everything inside, whereas the "soft" quote ("), allows certain things--eg variables-- to be expanded by the shell.
2. Quotes behave like "toggles" so, to turn off quoting for part of an expression, you just do as follows:
'stuff and 'unquoted stuff' more quoted stuff' ("unquoted stuff" might look like it was being quoted doubly, but it's just being UN-quoted.
Beyond this, I've never had any luck with anything except trial and error.
MAIL="/bin/mailx -s \'Error from $(basename $0)\' root"
However, you don't need to escape a different kind of quote. You don't need to escape single quotes inside double quotes. So try:
Code:
MAIL="/bin/mailx -s 'Error from $(basename $0)' root"
That will give you something like:
Code:
/bin/mailx -s 'Error from foo' root
as the string value in variable MAIL. The $(basename $0) part will be interpreted at the time of assignment to MAIL (e.g. using $0 from the command that did this assignment). If that's what you want, you should be good to go with this.
MAIL="/bin/mailx -s \'Error from $(basename $0)\' root"
However, you don't need to escape a different kind of quote. You don't need to escape single quotes inside double quotes. So try:
Code:
MAIL="/bin/mailx -s 'Error from $(basename $0)' root"
That will give you something like:
Code:
/bin/mailx -s 'Error from foo' root
as the string value in variable MAIL. The $(basename $0) part will be interpreted at the time of assignment to MAIL (e.g. using $0 from the command that did this assignment). If that's what you want, you should be good to go with this.
Nope; because the single quote won't expand the $(basename $0). It comes out
MAIL="/bin/mailx -s 'Error from $(basename $0)' root"
[root@dg scripts]# echo $MAIL
/bin/mailx -s 'Error from ' root
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.