[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sh vs. bash -xc 'a=b c=$a'
From: |
Oğuz |
Subject: |
Re: sh vs. bash -xc 'a=b c=$a' |
Date: |
Thu, 23 May 2024 05:57:05 +0300 |
On Thu, May 23, 2024 at 2:49 AM Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
> Only to note that this is not portable.
> The FreeBSD shell will not assign "b" to "c" for this one!
Nor will NetBSD sh. This lets you swap values of two variables without
using a third
$ x=1 y=2
$ x=$y y=$x
$ echo $x $y
2 1
And some Bourne shells expand command substitutions first
$ (exit 5)
$ x=$? y=`exit 10`
$ echo $x
10