[PLUG] Bash Script Error

wes plug at the-wes.com
Thu Jul 8 17:43:02 UTC 2010


I'm afraid there are multiple issues with this.

1. in Bash, you do not use the $ when setting the value of a variable. Also,
you don't need to tell it you are setting the value of the variable; you
Just Do It.

  all="cat list"

2. A "for" loop begins with a "do" command and ends with a "done" command.

  for x in $all;do 'cat msg2 | mailx -s "Test Message"' $x;done

3. You have single-quotes around 'cat msg2 | mailx -s "Test Message"' which
is going to tell Bash to treat the whole string as a single word. There is
no command named "cat msg2 | mailx -s "Test Message" that I am aware of.

  for x in $all;do cat msg2 | mailx -s "Test Message" $x;done

4. I'm not sure this is going to do what you think it's going to do. With
these commands, you're telling Bash to send an email to two addresses: "cat"
and "list" as specified in the variable $all. I assume you have a file named
"list" which you are trying to use the cat command to read. Try this:

  for x in $(cat list);do cat msg2 | mailx -s "Test Message" $x;done

I haven't tested it, so there could be plenty that I've missed. I expect the
above should at the very least provide a much more interesting error. :)

-wes

On Thu, Jul 8, 2010 at 10:30 AM, Rich Shepard <rshepard at appl-ecosys.com>wrote:

>   When I run this script:
>
> set $all="cat list"
> for x in $all; `cat msg2 | mailx -s "Test Message"' $x
>
>   I see this error:
>
> -bash: syntax error near unexpected token `cat msg2 | mailx -s "Test
> Message"'
>
>   What have I done incorrectly? Is it the semi-colon?
>
>   Typing on two lines (beaking after the semi-colon) makes no difference.
>
> Rich
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> http://lists.pdxlinux.org/mailman/listinfo/plug
>



More information about the PLUG mailing list