From: Salve =?ISO-8859-15?Q?H=E5kedal?= on
I want to use the select builtin to select filenames, and some of them
contains the character _

I want that character to be printed as whitespace when select runs.

Let's say I have these files:
Small_file
Medium_file
Big_file

running:
select f in *; do something; done

should print this:
1) Small file
2) Medium file
3) Big file
#?

Is it possible?

--
Salve
From: Icarus Sparry on
On Sun, 13 Dec 2009 21:17:52 +0000, Salve Håkedal wrote:

> I want to use the select builtin to select filenames, and some of them
> contains the character _
>
> I want that character to be printed as whitespace when select runs.
>
> Let's say I have these files:
> Small_file
> Medium_file
> Big_file
>
> running:
> select f in *; do something; done
>
> should print this:
> 1) Small file
> 2) Medium file
> 3) Big file
> #?
>
> Is it possible?

Yes, for example

FILES=(*)
select f in "${FILES[@]//_/ }"
do echo "$REPLY, $f, ${FILES[REPLY-1]}
break
done

Simpler constructs may be possible.




From: Salve =?ISO-8859-15?Q?H=E5kedal?= on
Icarus Sparry <usenet(a)icarus.freeuk.com> wrote:
> On Sun, 13 Dec 2009 21:17:52 +0000, Salve H�kedal wrote:
>
>> I want to use the select builtin to select filenames, and some of them
>> contains the character _
>>
>> I want that character to be printed as whitespace when select runs.
>>
>> Let's say I have these files:
>> Small_file
>> Medium_file
>> Big_file
>>
>> running:
>> select f in *; do something; done
>>
>> should print this:
>> 1) Small file
>> 2) Medium file
>> 3) Big file
>> #?
>>
>> Is it possible?
>
> Yes, for example
>
> FILES=(*)
> select f in "${FILES[@]//_/ }"
> do echo "$REPLY, $f, ${FILES[REPLY-1]}
> break
> done
>
> Simpler constructs may be possible.
>

(A '"' must be added at the end of the echo line.)

Thank you, this is interesting, and I learn several things from it!

Seems like arithmetic evaluation for array subscript is real simple to
write. Where can I read about that? Should I be able to find it with
'man bash'?

--
Salve
From: Icarus Sparry on
On Mon, 14 Dec 2009 12:24:54 +0000, Salve Håkedal wrote:

> Icarus Sparry <usenet(a)icarus.freeuk.com> wrote:
>> On Sun, 13 Dec 2009 21:17:52 +0000, Salve Håkedal wrote:
>>
>>> I want to use the select builtin to select filenames, and some of them
>>> contains the character _
>>>
>>> I want that character to be printed as whitespace when select runs.
>>>
>>> Let's say I have these files:
>>> Small_file
>>> Medium_file
>>> Big_file
>>>
>>> running:
>>> select f in *; do something; done
>>>
>>> should print this:
>>> 1) Small file
>>> 2) Medium file
>>> 3) Big file
>>> #?
>>>
>>> Is it possible?
>>
>> Yes, for example
>>
>> FILES=(*)
>> select f in "${FILES[@]//_/ }"
>> do echo "$REPLY, $f, ${FILES[REPLY-1]}
>> break
>> done
>>
>> Simpler constructs may be possible.
>>
>>
> (A '"' must be added at the end of the echo line.)

Oops, sorry!

> Thank you, this is interesting, and I learn several things from it!
>
> Seems like arithmetic evaluation for array subscript is real simple to
> write. Where can I read about that? Should I be able to find it with
> 'man bash'?

Yes, but you might need to read several different parts of the manual
page.

For the 4.033 version of bash I have in front of me, the manual says the
following

Arrays

Bash provides one-dimensional indexed and associative array variables.
Any variable may be used as an indexed array; the declare builtin will
explicitly declare an array. There is no maximum limit on the size
of an array, nor any requirement that members be indexed or assigned
contiguously. Indexed arrays are referenced using integers (including
arithmetic expressions) and are zero- based; associative arrays are
referenced using arbitrary strings.

An indexed array is created automatically if any variable is assigned
to using the syntax name[subscript]=value. The subscript is treated as
an arithmetic expression that must evaluate to a number greater than or
equal to zero.

The last sentence tells you that it uses an arithmetic expression as the
array index, and there is a small section on this, which points you to
ARITHMETIC EVALUATION. The latter tells you that you don't need to use
dollar signs, tells you that is does expressions as fixed-width
integers (probably 32 or maybe 64 bits) , that it has bitshift ops etc.
From: Salve =?ISO-8859-15?Q?H=E5kedal?= on
Icarus Sparry <usenet(a)icarus.freeuk.com> wrote:
> On Mon, 14 Dec 2009 12:24:54 +0000, Salve H�kedal wrote:
>
>> Icarus Sparry <usenet(a)icarus.freeuk.com> wrote:
>>> On Sun, 13 Dec 2009 21:17:52 +0000, Salve H�kedal wrote:
>>>
>>>> I want to use the select builtin to select filenames, and some of them
>>>> contains the character _
>>>>
>>>> I want that character to be printed as whitespace when select runs.
>>>>
>>>> Let's say I have these files:
>>>> Small_file
>>>> Medium_file
>>>> Big_file
>>>>
>>>> running:
>>>> select f in *; do something; done
>>>>
>>>> should print this:
>>>> 1) Small file
>>>> 2) Medium file
>>>> 3) Big file
>>>> #?
>>>>
>>>> Is it possible?
>>>
>>> Yes, for example
>>>
>>> FILES=(*)
>>> select f in "${FILES[@]//_/ }"
>>> do echo "$REPLY, $f, ${FILES[REPLY-1]}
>>> break
>>> done
>>>
>>> Simpler constructs may be possible.
>>>
>>>
>> (A '"' must be added at the end of the echo line.)
>
> Oops, sorry!
>
>> Thank you, this is interesting, and I learn several things from it!
>>
>> Seems like arithmetic evaluation for array subscript is real simple to
>> write. Where can I read about that? Should I be able to find it with
>> 'man bash'?
>
> Yes, but you might need to read several different parts of the manual
> page.
>
> For the 4.033 version of bash I have in front of me, the manual says the
> following
>
> Arrays
>
> Bash provides one-dimensional indexed and associative array variables.
> Any variable may be used as an indexed array; the declare builtin will
> explicitly declare an array. There is no maximum limit on the size
> of an array, nor any requirement that members be indexed or assigned
> contiguously. Indexed arrays are referenced using integers (including
> arithmetic expressions) and are zero- based; associative arrays are
> referenced using arbitrary strings.
>
> An indexed array is created automatically if any variable is assigned
> to using the syntax name[subscript]=value. The subscript is treated as
> an arithmetic expression that must evaluate to a number greater than or
> equal to zero.
>
> The last sentence tells you that it uses an arithmetic expression as the
> array index, and there is a small section on this, which points you to
> ARITHMETIC EVALUATION. The latter tells you that you don't need to use
> dollar signs, tells you that is does expressions as fixed-width
> integers (probably 32 or maybe 64 bits) , that it has bitshift ops etc.

Thanks again. I now find it in the manual, too. By reading more
carefully!

--
Salve