Bug 257702

Summary: /bin/sh: different behavior when chaining variable assignments
Product: Base System Reporter: dylan.araps
Component: standardsAssignee: freebsd-standards (Nobody) <standards>
Status: New ---    
Severity: Affects Only Me CC: dylan.araps, jilles
Priority: ---    
Version: 13.0-RELEASE   
Hardware: Any   
OS: Any   

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
1

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 freebsd_triage 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.