Bug 257702 - /bin/sh: different behavior when chaining variable assignments
Summary: /bin/sh: different behavior when chaining variable assignments
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-standards (Nobody)
Depends on:
Reported: 2021-08-09 07:09 UTC by dylan.araps
Modified: 2021-08-21 20:33 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description dylan.araps 2021-08-09 07:09:00 UTC
I am not sure if this is the right component to open this issue under. Apologies in advance if this is the wrong place.

Take the following example code:

$ a=1 b=$a

Expected behavior (tested in: ash (busybox), dash, bash, zsh, mirbsd ksh, openbsd ksh, yash, osh and pdsh):

# b is set to a which is 1
$ echo $b

Actual behavior (freebsd sh):

# just a newline
$ echo $b

Every other shell I have tried exhibits the "expected behavior". I do not know if this is a standards compliance issue or just a difference in behavior between freebsd sh and other shells.
Comment 1 Jilles Tjoelker freebsd_committer 2021-08-21 20:33:55 UTC
If FreeBSD sh is the odd one out here, it may be good to change this (although ports might contain stuff like a=$b b=$a to swap).

The exact rules about variable assignments in POSIX have changed via some interpretations, so the existing behaviour might still be POSIXly correct.