Bash - Command and variable expansion

160 Views Asked by At

After reading the POSIX Shell manual and the Bash manual I still can't explain the following behavior:

% bash --version
GNU bash, version 3.2.48(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
% bash
% A=1 B=$A bash -c 'echo $B'
1
% A=1 B=$A bash -c 'echo $B'

%

Other shells like zsh or ksh are doing what I would expect, which would be to display '1' all the time. So it seems to be specific to Bash.

Could someone explain this behavior and if possible point to where it's explained in the documentation?

Thanks in advance!

1

There are 1 best solutions below

0
On

This behaviour seems to be specific to Bash 3.2 and the snippet works as expected on later versions, as 4.2.