[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Assignment errors with no additional words expanded in non-POSIX mod
From: |
Chet Ramey |
Subject: |
Re: Assignment errors with no additional words expanded in non-POSIX mode fails to abort |
Date: |
Sat, 12 Jan 2013 18:17:03 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/17.0 Thunderbird/17.0 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 1/11/13 1:17 PM, Dan Douglas wrote:
> Whether or not this type of error aborts depends upon there being an actual
> newline.
It doesn't actually abort the script itself; the assignment error causes
the current command to be aborted. Posix mode does cause script exit.
> $ bash -c 'echo pre; foo=$((8#9)); echo post' 2>&1
> pre
> bash: 8#9: value too great for base (error token is "8#9")
>
> $ bash -c $'echo pre\nfoo=$((8#9))\necho post' 2>&1
> pre
> bash: line 1: 8#9: value too great for base (error token is "8#9")
> post
This is one place where newlines and semicolons are not equivalent. The
semicolons in the first command result in a single command (a list). The
newlines in the second case result in three commands (remember that bash
always reads a line at a time).
When the expansion error in the assignment causes the current command to
abort, it has different effects based on whether that command is a list or
a simple command.
Chet
- --
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/
iEYEARECAAYFAlDx7ugACgkQu1hp8GTqdKsyCACffqXF4/EmgmpX6tbB/a7EwSYc
rGYAni0Z2e7DaUIZFOa9BZlB2maNH6Xq
=rB3G
-----END PGP SIGNATURE-----