[Bug 1381567] Re: Bash returns unexpected character \001 on string operation
xhienne
1381567 at bugs.launchpad.net
Mon Jun 19 17:24:08 UTC 2017
Affects xenial too. There is definitely something wrong.
Several notes on this:
1. A direct call to "echo ${f[@]:0:1}" outputs "a". The problems thus
lies in the variable assignment.
2. If first_char=${f[@]:0:1}, then echo "$first_char" outputs \001 but
"declare -p first_char" outputs \001\001
3. Double-quoted first_char="${f[@]:0:1}" puts "a" in first_char like in
Precise
4. first_char=${f[*]:0:1} has the same behaviour
5. Anyway, proper syntax should be first_char=${f:0:1} since you
consider f as a string. If you want to force bash to consider f as an
array (with the ${f[@]} syntax), then first_char=${f[@]:0:1} should put
f[0] in first_char, that is "abcd", not "a". So IMHO both Precise and
Trusty results are wrong.
** Tags added: xenial
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to bash in Ubuntu.
https://bugs.launchpad.net/bugs/1381567
Title:
Bash returns unexpected character \001 on string operation
Status in bash package in Ubuntu:
Confirmed
Bug description:
There has been some change between Precise and Trusty that lets this code snippet behave differently:
Precise:
$ unset f ; f=abcd ; first_char=${f[@]:0:1} ; echo $first_char
a
Trusty
$ unset f ; f=abcd ; first_char=${f[@]:0:1} ; echo $first_char
\001
The solution is to use ${f:0:1} but nevertheless the result on Trusty seems completely wrong. Where does the \001 even come from?!
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1381567/+subscriptions
More information about the foundations-bugs
mailing list