Bug 427184 - Can't assign a variable to "[x]"
Can't assign a variable to "[x]"
Product: Fedora
Classification: Fedora
Component: bash (Show other bugs)
All Linux
low Severity low
: ---
: ---
Assigned To: Tomas Janousek
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2008-01-01 22:55 EST by H.J. Lu
Modified: 2008-01-02 11:49 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2008-01-02 11:49:40 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description H.J. Lu 2008-01-01 22:55:53 EST
bash-3.2-9.fc7 won't assign a variable to "[x]":

[hjl@gnu-6 gsse-tests]$ a="[t]"; echo $a
[hjl@gnu-6 gsse-tests]$ a="[x]"; echo $a
[hjl@gnu-6 gsse-tests]$ a="[y]"; echo $a
Comment 1 Jon Stanley 2008-01-01 23:18:47 EST
I'm surprised any of that worked.  You need to use single quotes, not double,
when using shell special characters as values to a variable.

Or am I missing something here?
Comment 2 Jon Stanley 2008-01-01 23:19:34 EST

[jstanley@rugrat ~]$ a='[x]' ; echo $a
Comment 3 Tomas Janousek 2008-01-02 04:23:44 EST
Yeah, Jon is right.

[tomi@notes tmp]$ a="[x]"; echo $a
[tomi@notes tmp]$ touch x
[tomi@notes tmp]$ a="[x]"; echo $a

Comment 4 H.J. Lu 2008-01-02 08:57:13 EST
[hjl@gnu-6 gsse-tests]$ which foox
/usr/bin/which: no foox in
[hjl@gnu-6 gsse-tests]$ ls -l foox
ls: cannot access foox: No such file or directory
[hjl@gnu-6 gsse-tests]$ a='[foox]'; echo $a
[hjl@gnu-6 gsse-tests]$ ls -l x
-rwxr-xr-x 1 hjl hjl 82 2008-01-01 19:24 x
[hjl@gnu-6 gsse-tests]$ a='[foox]'; echo $a
[hjl@gnu-6 gsse-tests]$ touch x
[hjl@gnu-6 gsse-tests]$ a='[foox]'; echo $a
[hjl@gnu-6 gsse-tests]$ a="[foox]"; echo $a
[hjl@gnu-6 gsse-tests]$ zsh
gnu-6:pts/43[1]> a="[foox]"; echo $a
gnu-6:pts/43[2]> a='[foox]'; echo $a

It looks like I can't have x in my current directory. Otherwise, none of
"[XXXXXx]" or '[XXXXXx]' will work.
Comment 5 Tomas Janousek 2008-01-02 10:04:28 EST
Oh, seems like it's getting expanded somewhere else, in "echo $a".
Try a="[foox]"; echo "$a"
Comment 6 H.J. Lu 2008-01-02 10:12:51 EST
a="[foox]"; echo "$a" works. But it doesn't make any senses since there is
no foox anywhere on my machine.
Comment 7 Tomas Janousek 2008-01-02 10:24:23 EST
See the Pathname Expansion section of the manpage.
Comment 8 H.J. Lu 2008-01-02 11:49:40 EST
OK, I will live with it.

Note You need to log in before you can comment on or make changes to this bug.