|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
$file is a list of email addresses separated by newlines e.g.
me@somewhere.com, he@nowhere.com, she@faraway.com When I then expand the variable (which is actually ${RECIPIENTS}, my shell script sends email to the first recipient only (fortunately, me) and then sends the rest of the list to standard output (the email message being generated). Does bash always retain the newlines in a variable assignment? Is that a difference between bash and the Bourne shell? Should I just generate the file as a one-line list to solve this problem? Thanks for any . |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Fri, 27 Jul 2007 17:02:53 -0000, paintedjazz@gmail.com
<paintedjazz@gmail.com> wrote: > > > $file is a list of email addresses separated by newlines e.g. > > me@somewhere.com, > he@nowhere.com, > she@faraway.com > > When I then expand the variable (which is actually ${RECIPIENTS}, my > shell script sends email to the first recipient only (fortunately, me) > and then sends the rest of the list to standard output (the email > message being generated). Does bash always retain the newlines in a > variable assignment? Is that a difference between bash and the Bourne > shell? Should I just generate the file as a one-line list to solve > this problem? Thanks for any . > You could use: set $(cat "$file") mailx -s "subject" $* < "$message_file" You could also use xargs, but might need a wrapper script to redirect the message text into mailx. -- Pete: Waiter, this meat is bad. Waiter: Who told you? Pete: A little swallow. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
paintedjazz@gmail.com wrote:
> $file is a list of email addresses separated by newlines e.g. > > me@somewhere.com, > he@nowhere.com, > she@faraway.com > > When I then expand the variable (which is actually ${RECIPIENTS}, my > shell script sends email to the first recipient only (fortunately, me) > and then sends the rest of the list to standard output (the email > message being generated). Does bash always retain the newlines in a > variable assignment? Is that a difference between bash and the Bourne > shell? Should I just generate the file as a one-line list to solve > this problem? Thanks for any . > Yes they are retained in sh/ksh/bash. set -f mail ${RECIPIENTS} should work nevertheless, only mail "${RECIPIENTS}" will retain the lines. The set -f is to suppress "globbing". If RECIPIENTS is loaded from a file, you can as well directly do set -f mail `cat file_with recipients` -- Michael Tosch @ hp : com |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Please put all the information in the body of the article; don't
put it only in the subject line. On 2007-07-27, paintedjazz@gmail.com wrote: > > VAR=$( cat $file ) what's wrong with this? > > $file is a list of email addresses separated by newlines e.g. Nothing's wrong with it; in bash you can save an external command and use: VAR=$( < $file ) > me@somewhere.com, > he@nowhere.com, > she@faraway.com Thos are not separated by newlines; they are separated by commas and newlines. > When I then expand the variable (which is actually ${RECIPIENTS}, my > shell script sends email to the first recipient only (fortunately, me) > and then sends the rest of the list to standard output (the email > message being generated). Does bash always retain the newlines in a > variable assignment? Is that a difference between bash and the Bourne > shell? All Bourne-type shells retain all newlines except trailing ones. > Should I just generate the file as a one-line list to solve > this problem? Thanks for any . How are you using the variable? If you are quoting it, the newlines will be retained; if you don't, they won't. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
"Chris F.A. Johnson" <cfajohn...@gmail.com> wrote:
> ... > Nothing's wrong with it; in bash you can save an external command > and use: > VAR=$( < $file ) > ... Ksh too. Came from there. =Brian |
|
![]() |
| Outils de la discussion | |
|
|