help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] getting weird output out of 'echo' w/args


From: Roman Rakus
Subject: Re: [Help-bash] getting weird output out of 'echo' w/args
Date: Thu, 30 May 2013 12:38:00 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4

I agree. Other than C or POSIX locales' collations order are not specified. It means on some machine it can result in aäáàâbc, where on other it can be aäáàâAbBc. Even worse I also saw bad order of file names with en_US locales (only US letters), so it is not reliable.

RR

On 05/30/2013 12:25 PM, John Kearney wrote:
And note, if you do try using globbing, for constructs like [a-z] to work
as you probably expect, you need to set
LC_COLLATE=C
otherwise [a-z] can end up being something like
[aäáàâbc...  z]
  which is normally not what was intended.


On Thu, May 30, 2013 at 11:15 AM, Roman Rakus <address@hidden> wrote:

Changing the list to help-bash, I think this belongs here.

This is common misconception about filename expansion (globbing). Since
globbing is done nearly always (*) people know only about "star" character.
The fact is that "star", "question mark" and "opening bracket" (*, ?, [)
all have special meaning for globbing. See http://www.gnu.org/software/**
bash/manual/bashref.html#**Filename-Expansion<http://www.gnu.org/software/bash/manual/bashref.html#Filename-Expansion>

Many times I saw using tr like this:
somecommand | tr -s [a-z] ''
somecommand | tr -s [:space:] ' '

Please note that argument for tr undergo globbing (by bash), because it is
not quoted.

RR

* It's not always, but it is good practise to double-quote variable
expansions.

On 05/30/2013 10:56 AM, Chris Down 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


$



On 30 May 2013 16:49, Davide Brini <address@hidden> wrote:

On Thu, 30 May 2013 08:53:48 +0300, Pierre Gaston <
address@hidden>
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.










reply via email to

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