0

While attempting to debug a job submission script, I ended up narrowing down the bug to this:

    [testuser@bes ~]$ var=( 1 foo1*bar4 echo 1*4=4 )
    [testuser@bes ~]$ echo "${var[@]}"
    1 foo1*bar4 echo 1*4=4
    [testuser@bes ~]$ cd /data/testuser/jobs/example/a16162/
    [testuser@bes a16162]$ var=( 1 foo1*bar4 echo 1*4=4 )
    [testuser@bes a16162]$ echo "${var[@]}"
    1 foo1-bar4 foo1*bar4 echo 1*4=4
    [testuser@bes a16162]$

That is an uncut transcript of a fresh bash session. Anyone have any idea how that one works? Is this some archaic feature of bash that I've never heard of before, or just a really weird bug?

Versions (yes I know it's out dated):

GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Linux bes 2.6.18-194.11.3.el5 #1 SMP Mon Aug 30 16:19:16 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

EDIT: This is for something that needs to process a user-passed array, and I'd rather use this method than a triplet of rather awkward awk hacks. They're trivial "extract element 2" sorts of things, which is why using the array seems nicer.

0

2 Answers 2

2

Globs are still globbed when the array is formed. If you don't want this then you need to quote or escape them.

$ var=( 1 "foo1*bar4" echo "1*4=4" )
Sign up to request clarification or add additional context in comments.

3 Comments

!!!! Why did I not think of that; I knew it had to be folder-dependent, but somehow missed that. Thankyou much. I don't think I can quote var=( $l ), so I guess I'll just use cut.
@zebediah49 certainly you can quote var=( "$l" )... unless what you really want is to string-split but not glob-expand $l? That's possible too, but you need to tell us what you want before we can tell you how to do it.
I vaguely touched on it, but I want to split the string, without anything else happening. Specifically, I need ${var[0]}, ${var[1]}, and ${var[@]:2}. awk will do this, just somewhat awkwardly.
1

What does ls /data/testuser/jobs/example/a16162/foo1* reveal?

You can disable filename globbing with set -f and re-enable it with set +f

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.