mailx and variables?

  • Follow


I can do this

mailx -s "hello bob" me@world.com <myfile

and I get an email with myfile's content in body.


but I need to store the subject, addresses and file name from in
variables so I can do this

maix -s $subj $emailto < $file

understanding that subject and emailto might have spaces, I store them
with the quotes

so

echo $subj

displays

"hello bob" quotes and all..

Still , I get an error saying bob is an unknown user

0
Reply jobs235 (25) 9/8/2007 7:43:49 PM

On Sat, 08 Sep 2007 12:43:49 -0700, jobs wrote:

> "hello bob" quotes and all..
> 
> Still , I get an error saying bob is an unknown user

Try using single quotes instead.
0
Reply Dave 9/8/2007 7:52:14 PM


jobs wrote:
> but I need to store the subject, addresses and file name from in
> variables so I can do this
> 
> mailx -s $subj $emailto < $file

mailx -s "$subj" "$emailto" < "$file"
0
Reply Oscar 9/8/2007 10:31:01 PM

In article <13e5vbebr0noga2@news.supernews.com>,
 Dave Uhring <daveuhring@yahoo.com> wrote:

> On Sat, 08 Sep 2007 12:43:49 -0700, jobs wrote:
> 
> > "hello bob" quotes and all..
> > 
> > Still , I get an error saying bob is an unknown user
> 
> Try using single quotes instead.

That won't work as single quotes don't expand variables.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
Reply Michael 9/9/2007 12:50:22 AM

jobs <jobs@webdos.com> writes:
>
>but I need to store the subject, addresses and file name from in
>variables so I can do this
>
>maix -s $subj $emailto < $file
>
>understanding that subject and emailto might have spaces, I store them
>with the quotes
>

Someone else has already posted the short solution, but I want to
mention that your last remark is not a good idea in general.

The better idea is to put quotes where they are needed.  In this
case, quotes are needed on the mailx command line.  You shouldn't
try to embed extra quotes into the values you put into the variables.

I.e., this is the wrong approach:

  subj="'This is a test message'"
  emailto="'user1@example.com user2@example.com'"
  filename=/path/to/email/file
  mailx -s $subj $emailto < $filename

this is the right one:

  subj="This is a test message"
  emailto="user1@example.com user2@example.com"
  filename=/path/to/email/file
  mailx -s "$subj" "$emailto" < $filename


So in the lines where you assign values to variables you use only
the quotes necessary for the assignment.  Later, when you use the
values on the mailx command line, you use the quotes needed for
the values to be handled properly there.  You don't embed extra
quotes in the assignment lines that will take effect on the mailx
command line.

As with all rules, there are exceptions.  I.e. situations where you
must embed extra quotes to be used later in the script.  However,
they're pretty rare, and your script is not one of them.

  -Greg
-- 
Do NOT reply via e-mail.
Reply in the newsgroup.
0
Reply gerg 9/9/2007 3:34:03 AM

4 Replies
620 Views

(page loaded in 0.444 seconds)

Similiar Articles:













7/23/2012 12:27:43 AM


Reply: