[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
mysteries with the placeholder variable _
From: |
Léa Gris |
Subject: |
mysteries with the placeholder variable _ |
Date: |
Sat, 12 Dec 2020 23:51:19 +0100 |
User-agent: |
Telnet/1.0 [tlh] (PDP11/DEC) |
# GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
bash -c 'unset _;_=42;echo $_;unset _;: $((_=666));echo "$_"'
666
# ksh version sh (AT&T Research) 93u+ 2012-08-01
ksh -c 'unset _;_=42;echo $_;unset _;: $((_=666));echo "$_"'
42
-3,02546243348e-123
# zsh 5.8 (x86_64-ubuntu-linux-gnu)
zsh -c 'unset _;_=42;echo $_;unset _;: $((_=666));echo "$_"'
666
# dash 0.5.10.2-7
zsh -c 'unset _;_=42;echo $_;unset _;: $((_=666));echo "$_"'
42
666
It raises multiple observations:
- I thought the placeholder variable _ was a sinkhole like /dev/null. It
seems like it can get assigned values within arithmetic expressions in
bash, dash and zsh
- The weird working of ksh if out of scope here, look like any number
not power of 2 produces the strange output that is not even an integer.
- Dash seems to handle _ as a regular variable and accept assignment,
which is probably conformant to POSIX shell specifications.
--
Léa Gris
- mysteries with the placeholder variable _,
Léa Gris <=