bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nitpick: a=([9223372036854775807]=1 2 3)


From: Stephane Chazelas
Subject: nitpick: a=([9223372036854775807]=1 2 3)
Date: Tue, 16 Dec 2014 22:10:49 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

bash-4.3$ a=([9223372036854775806]=1 2 3 4)
bash-4.3$ echo "address@hidden"
-9223372036854775808 -9223372036854775807 9223372036854775806 
9223372036854775807

That wraps but as signed longs, which means we get negative
indexes which we can't easily use.

bash-4.3$ echo "address@hidden"
3 4 1 2
bash-4.3$ for i in "address@hidden"; do echo "${a[i]}"; done


1
2
bash-4.3$ echo "${a[-1]}"
2
bash-4.3$ echo "${a[-2]}"
1
bash-4.3$ echo "${a[-3]}"

bash-4.3$ echo "${a[-4]}"

bash-4.3$ echo "address@hidden:0:4}"
1 2
bash-4.3$ echo "address@hidden: -1:1}"

bash-4.3$ echo "address@hidden: -4:1}"


Same with a[9223372036854775807]; a+=(1 2 3)

mksh wraps to 0 at 2^32 and ksh93 at 2^22 (!?).

zsh arrays are not sparse.

-- 
Stephane





reply via email to

[Prev in Thread] Current Thread [Next in Thread]