Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting weird output out of 'echo' w/args

3 views
Skip to first unread message

Linda Walsh

unread,
May 29, 2013, 9:08:55 PM5/29/13
to bug-bash
Why would I get this:

> echo "gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]"
gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]

> echo gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]
gtk-2.0/2.10.0/engines/liboxygen-gtk.so s

^^--so why doesn't it echo out it's input arguments? Where did the acl go?
into 's'? ;-/

bash ver=4.2.45(1)-release

options (shopt):
+autocd +cdable_vars +cdspell +checkhash -checkjobs +checkwinsize
+cmdhist -compat31 -compat32 -compat40 -compat41 -direxpand +dirspell
+dotglob -execfail +expand_aliases -extdebug +extglob +extquote -failglob
+force_fignore +globstar -gnu_errfmt +histappend +histreedit +histverify
+hostcomplete -huponexit +interactive_comments -lastpipe +lithist
+login_shell -mailwarn +no_empty_cmd_completion +nocaseglob +nocasematch
-nullglob +progcomp +promptvars -restricted_shell -shift_verbose
+sourcepath +xpg_echo
(set):
-allexport +braceexpand -emacs -errexit -errtrace -functrace +hashall
-histexpand +history -ignoreeof +interactive-comments -keyword +monitor
-noclobber -noexec -noglob -nolog -notify -nounset -onecmd -physical
+pipefail -posi-privileged -verbose +vi -xtrace

====
Is this something peculiar to my distro again, or hopefully something
with simpler explanation? Maybe the [] have some meta meaning now
on output? Weird...






Chet Ramey

unread,
May 29, 2013, 9:25:06 PM5/29/13
to Linda Walsh, bug-bash, chet....@case.edu
On 5/29/13 9:08 PM, Linda Walsh wrote:
> Why would I get this:
>
>> echo "gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]"
> gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]
>
>> echo gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]
> gtk-2.0/2.10.0/engines/liboxygen-gtk.so s
>
> ^^--so why doesn't it echo out it's input arguments? Where did the acl go?
> into 's'? ;-/

Are you familiar with filename generation, commonly known as `globbing'?

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/

Linda Walsh

unread,
May 29, 2013, 9:42:43 PM5/29/13
to bug-bash


Chet Ramey wrote:
> On 5/29/13 9:08 PM, Linda Walsh wrote:
>> Why would I get this:
>>
>>> echo "gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]"
>> gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]
>>
>>> echo gtk-2.0/2.10.0/engines/liboxygen-gtk.so [u::rwx,u:law:rwx,g::r-x,m::rwx,o::r-x]
>> gtk-2.0/2.10.0/engines/liboxygen-gtk.so s
>>
>> ^^--so why doesn't it echo out it's input arguments? Where did the acl go?
>> into 's'? ;-/
>
> Are you familiar with filename generation, commonly known as `globbing'?
>


Are you saying it took bracketed thing as a gorup of chars to match?
oh... and the r-x was a range that picked up a singled file 's'... ARG!...
oi oi oi...

Thanks -- I was hoping it has some simple explanation that I just wasn't seeing.
(I was only thinking of escape sequences...)...

Cheers!
Linda

Pierre Gaston

unread,
May 30, 2013, 1:53:48 AM5/30/13
to Linda Walsh, bug-bash
Missing quotes around [ ] can be nasty eg

#!/bin/bash
shopt -s nullglob # sounds a good idea!
.....
.....
i=0
while read a[i++]; do
echo "${a[i]}" # why oh why nothing is printed!
done <<< "hello"

Davide Brini

unread,
May 30, 2013, 4:49:57 AM5/30/13
to bug-...@gnu.org
On Thu, 30 May 2013 08:53:48 +0300, Pierre Gaston <pierre...@gmail.com>
wrote:

> Missing quotes around [ ] can be nasty eg
>
> #!/bin/bash
> shopt -s nullglob # sounds a good idea!
> .....
> .....
> i=0
> while read a[i++]; do
> echo "${a[i]}" # why oh why nothing is printed!
> done <<< "hello"

It seems to me this has nothing to do with missing quotes around [ ], or I
don't get what you mean.

--
D.

Chris Down

unread,
May 30, 2013, 4:56:36 AM5/30/13
to Davide Brini, bug-bash
Pierre is referring to the fact that [i++] is evaluated as a glob by
the shell, the reason it doesn't work is because $i is postincremented
instead of preincremented. You can see what he means here:

$ shopt -u nullglob
$ i=0
$ while read a[++i]; do
> echo "${a[i]}"
> done <<< hello
hello
$ shopt -s nullglob
$ while read a[++i]; do
> echo "${a[i]}"
> done <<< hello

$

Davide Brini

unread,
May 30, 2013, 5:04:47 AM5/30/13
to bug-...@gnu.org
On Thu, 30 May 2013 16:56:36 +0800, Chris Down <ch...@chrisdown.name> wrote:

> Pierre is referring to the fact that [i++] is evaluated as a glob by
> the shell, the reason it doesn't work is because $i is postincremented
> instead of preincremented. You can see what he means here:
>
> $ shopt -u nullglob
> $ i=0
> $ while read a[++i]; do
> > echo "${a[i]}"
> > done <<< hello
> hello
> $ shopt -s nullglob
> $ while read a[++i]; do
> > echo "${a[i]}"
> > done <<< hello
>
> $

But he was doing postincrement, so it wouldn't have worked anyway, since
the code was assigning to a[0] and printing a[1].

PS: Better put a

a=()

before each run.

--
D.

Chris Down

unread,
May 30, 2013, 5:06:08 AM5/30/13
to Davide Brini, bug-bash
That's... why I said he was unintentionally doing postincrement...

Pierre Gaston

unread,
May 30, 2013, 5:07:42 AM5/30/13
to Davide Brini, bug-...@gnu.org
On Thu, May 30, 2013 at 12:04 PM, Davide Brini <dav...@gmx.com> wrote:
> On Thu, 30 May 2013 16:56:36 +0800, Chris Down <ch...@chrisdown.name> wrote:
>
>> Pierre is referring to the fact that [i++] is evaluated as a glob by
>> the shell, the reason it doesn't work is because $i is postincremented
>> instead of preincremented. You can see what he means here:
>>
>> $ shopt -u nullglob
>> $ i=0
>> $ while read a[++i]; do
>> > echo "${a[i]}"
>> > done <<< hello
>> hello
>> $ shopt -s nullglob
>> $ while read a[++i]; do
>> > echo "${a[i]}"
>> > done <<< hello
>>
>> $
>
> But he was doing postincrement, so it wouldn't have worked anyway, since
> the code was assigning to a[0] and printing a[1].
>
> PS: Better put a
>
> a=()
>
> before each run.
>
> --
> D.

ok sorry for not having try my example, my point is that it was not
assigning to a[0] because of the nullglob and that this one can be
hard to spot

Davide Brini

unread,
May 30, 2013, 5:16:59 AM5/30/13
to bug-...@gnu.org
On Thu, 30 May 2013 17:06:08 +0800, Chris Down <ch...@chrisdown.name> wrote:

> That's... why I said he was unintentionally doing postincrement...

Doh! Indeed you said that. Apologies for reading too fast.

--
D.

Linda Walsh

unread,
May 30, 2013, 5:59:43 AM5/30/13
to bug-bash


Pierre Gaston wrote:

> ok sorry for not having try my example, my point is that it was not
> assigning to a[0] because of the nullglob and that this one can be
> hard to spot
---
Generally don't feel good about that op except in very narrow
circumstances...for exactly those types of reasons...what you
can't see CAN hurt you! ;-)

Chris Down

unread,
May 30, 2013, 6:02:35 AM5/30/13
to Linda Walsh, bug-bash
On 30 May 2013 17:59, Linda Walsh <ba...@tlinx.org> wrote:
> Generally don't feel good about that op except in very narrow
> circumstances...for exactly those types of reasons...what you
> can't see CAN hurt you! ;-)

It doesn't have anything to do with the operator, it's to do with the
usage of square brackets to indicate the index.

Linda Walsh

unread,
May 30, 2013, 6:46:54 AM5/30/13
to bug-bash
And here I thought it was my cross-circuiting to B that did the trick....


0 new messages