printf width format specifier doesn't work when assigned

2025-01-25 Thread Ross


Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-
frame-pointer -flto=auto -ffat-lto-objects -fstack-protector-strong -
fstack-clash-protection -Wformat -Werror=format-security -fcf-
protection -Wall
uname output: Linux X220-Bravo 6.8.0-51-generic #52-Ubuntu SMP
PREEMPT_DYNAMIC Thu Dec  5 13:09:44 UTC 2024 x86_64 x86_64 x86_64
GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 21
Release Status: release

Description:
>From the command line
printf "%*s\n" 80 " " | tr " " "*"
does just what I'd expect generating a banner line of asterisks.

However:
foo=$(printf "%*s\n" 80 " " | tr " " "*")
echo $foo
acts very differently; it seems to perform ls or something similar.

The same occurs with the more standard printf "%80s" form. 

Repeat-By:
As above.

Fix:
Unknown.




Cannot shadow local -r when assigning local to array in declaration

2020-04-23 Thread Ross Goldberg
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin19.3.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC -Wno-parentheses
-Wno-format-security
uname output: Darwin Thrawn.local 19.4.0 Darwin Kernel Version 19.4.0: Wed
Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin19.3.0

Bash Version: 5.0
Patch Level: 16
Release Status: release

Description:
If a function, f, declares a local readonly variable, v, using local -r, an
error occurs if f calls another function, g, that declares its own local
variable v (therefore shadowing v from f) and that assigns v to an array in
the same statement as the shadowing declaration.

g can, however, assign v to a scalar in a shadowing declaration.

g can also assign a shadowing v to an array, as long as it isn't assigned
in the same statement as the declaration.

Repeat-By:

function aaa() {
local x='1 2 3'
echo "aaa ${x}"
}

function bbb() {
local x
x=(4 5 6)
echo "bbb ${x[*]}"
}

function ccc() {
local x=(7 8 9)
echo "ccc ${x[*]}"
}

function ddd() {
local -r x='0'
echo "ddd ${x}"
aaa
bbb
ccc
}

ddd

# the above outputs the following:

ddd 0
aaa 1 2 3
bbb 4 5 6
bash: x: readonly variable