Re: [LTP] [PATCH] Fix some bashisms

Mike Frysinger
2009-07-06T22:02:22Z

[-- Attachment #1.1: Type: text/plain, Size: 1541 bytes --]

On Monday 06 July 2009 13:45:08 Garrett Cooper wrote:
> 2. All numeric test(1) comparisons could and should be switched from:
>
> command
> if [ $? = 0 ]; then
>
> to:
>
> if command; then
>
> for brevity.

that works the command is sufficiently short. if it's a long command and/or
has line wrappings itself, i find nesting it in the if statement makes the
situation much worse.

> 3. About &>
>
> Redirecting Standard Output and Standard Error
> Bash allows both the standard output (file descriptor 1) and
> the standard error output (file descriptor 2) to be redirected to the
> file whose name is the expansion of word with this construct.
>
> There are two formats for redirecting standard output and standard
> error:
>
> &>word
> and
>
> >&word
>
> The output redirection above captures all output (and most of the time
> you're capturing stdout, but losing stderr to the operating console,
> which can be undesirable). >& is more portable IIRC (it works with
> many ash variants, like FreeBSD's sh -- for sure -- and Solaris's sh
> -- IIRC), which makes it more ideal than &>.

what bash does doesnt matter. the redirection used needs to be in POSIX:
http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07

the "&>" form is not in POSIX, so should never be used. the ">&" format
cannot be used in POSIX without a word argument (you didnt say it could, just
making sure things are kept explicit).
-mike

[-- Attachment #1.2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 79 bytes --]

------------------------------------------------------------------------------

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]