PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > VAR=$( cat $file ) what's wrong with this?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

VAR=$( cat $file ) what's wrong with this?

Réponse
 
LinkBack Outils de la discussion
Vieux 27/07/2007, 18h02   #1
paintedjazz@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut VAR=$( cat $file ) what's wrong with this?

$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 .

  Réponse avec citation
Vieux 27/07/2007, 19h04   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: VAR=$( cat $file ) what's wrong with this?

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.
  Réponse avec citation
Vieux 27/07/2007, 22h01   #3
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: VAR=$( cat $file ) what's wrong with this?

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
  Réponse avec citation
Vieux 28/07/2007, 19h44   #4
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: VAR=$( cat $file ) what's wrong with this?

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
  Réponse avec citation
Vieux 02/08/2007, 02h42   #5
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: VAR=$( cat $file ) what's wrong with this?

"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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12905 seconds with 13 queries