bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Document m=1 m=2; echo $m result


From: Robert Elz
Subject: Re: Document m=1 m=2; echo $m result
Date: Mon, 03 Jul 2023 19:41:07 +0700

    Date:        Sun, 2 Jul 2023 21:04:38 -0400
    From:        Greg Wooledge <greg@wooledge.org>
    Message-ID:  <ZKIepsrizkqZeSf+@wooledge.org>

  | The first assignment is done before the value of "m" is used in the second
  | assignment.

Note that that is a shell specific feature, applies to bash, but
not necessarily to other shells (some will do it that way, others won't).

  | This feature is commonly used in the following constructs:
  |     extract=${input#*<} extract=${extract%>*}
  |     data=$(cat file; printf x) data=${data%x}

which would be made truly portable if written

        extract=${input#*<}; extract=${extract%>*}
        data=$(cat file; printf x); data=${data%x}

Is there really that much to be gained by omitting a semicolon
in a sequence like that?   The only time it matters if if the
assignments in question are prefixes to some other command.  Rather
than relying upon that kind of non-portable construct, you'd be better
to restructure the code, and avoid the issue, but this is very rare
except when someone is deliberately trying to make things non-portable.

kre




reply via email to

[Prev in Thread] Current Thread [Next in Thread]