zsh: substitute-if-undef-or-null for $1, $2 …: ${1:substitution} doesn't work
0
votes
2
answers
104
views
I'd like to have standard parameters, i.e., my minimum reproducible example is:
#!/usr/bin/zsh
a=${1:a}
printf 'a: "%s"\n' "${a}"
b=${2:./build}
printf 'b: "%s"\n' "${b}"
I'd expect to see, when running ./demo.zsh
without arguments:
a: "a"
b: "./build"
Instead I get
a: ""
./demo.zsh:4: bad floating point constant
- why does ${1:a}
seem to assume $1
to be set and non-zero, but the $a
expanded is empty string?
- where does the floating point misparsing come from? If I replace ./build
with build
, it complains about b
being an unknown modifier.
If I run ./demo.zsh asdf bar
, I get
a: "/tmp/fasf"
./demo.zsh:4: bad floating point constant
which, frankly is even more confusing; where does /tmp/
come from (it's the cwd).
Asked by Marcus Müller
(47272 rep)
Mar 10, 2025, 10:39 AM
Last activity: Mar 10, 2025, 05:12 PM
Last activity: Mar 10, 2025, 05:12 PM