Re: SHELLdorado Newsletter 1/2005 - April 30th, 2005

From: Heiner Steven (heiner.steven_at_nexgo.de)
Date: 05/02/05


Date: Mon, 02 May 2005 22:16:35 +0200

Stephane CHAZELAS wrote:

[...]
> As other pointed out:
>
> while IFS= read -r line <&3; do
> printf '%s\n' "$line" # echo should be banished
> done 3< "$file"

"printf" has its own share of problems, one of which
I ran into recently:

     printf "%d\n" 020 080

shows different behaviour for different operating systems,
and even different versions thereof.

020 is POSIX'ly correct interpreted as an octal number (16 decimal),
but "080" can result either in an "invalid number" error,
or in a silent conversion to decimal, resulting in the
output "80".

[...]
> Note that in the Bourne Shell, IFS= read line, sets IFS not only
> for the duration of "read" [...]

That's the problem I once had with this approach, thank
you Stephane for reminding me ;-)

[...many valid comments omitted...]

>>-----------------------------------------------------------------
>>
>>>>Shell Tip: How to avoid "Argument list too long" errors
>>
>>-----------------------------------------------------------------
>>
>> Oh no, there it is again: the system's spool directory is
>> almost full (4018 files); old files need to be removed, and
>> all useful commands only print the dreaded "Argument list
>> too long":
>>
>> $ cd /var/spool/data
>> $ ls *
>> ls: Argument list too long
>> $ rm *
>> rm: Argument list too long

> ls ./* rm ./*
> or
> ls -- * rm -- *

This should be used to make the command work with names containing
e.g. leading dashes. (As you probably know) it does not help
with the "Argument list too long" error.

Heiner

-- 
  ___ _
/ __| |_ _____ _____ _ _     Heiner STEVEN <heiner.steven@nexgo.de>
\__ \  _/ -_) V / -_) ' \    Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_|   http://www.shelldorado.com/


Relevant Pages