Re: [opensuse] BASH - better way to get total number of files matching glob??



On Thu, 27 May, 2010 at 03:11:18 -0500, David C. Rankin wrote:
On 05/26/2010 02:05 AM, Jon Clausen wrote:
Haven't tested it, but I'm pretty sure files with whitespace will break
this, but you get the idea

That's what IFS=$'\n' is for :p

Indeed... however:

Now I *have* tested, and somewhat surprisingly (to me at least) filenames
with whitespace are not a problem:

jon@nx8220:~/tmp/test> ll
total 0
-rw-r--r-- 1 jon users 0 2010-05-27 11:39 file no1
-rw-r--r-- 1 jon users 0 2010-05-27 11:39 file no2
drwxr-xr-x 3 jon users 17 2010-04-21 09:32 Folder1
jon@nx8220:~/tmp/test> array=(*)
jon@nx8220:~/tmp/test> echo ${array[@]}
file no1 file no2 Folder1
jon@nx8220:~/tmp/test> echo ${#array[@]}
3
jon@nx8220:~/tmp/test> echo ${array[0]}
file no1
jon@nx8220:~/tmp/test> echo ${#array[0]}
8

so there :)

/jon


--
YMMV
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx



Relevant Pages

  • Re: [opensuse] Need help doing a batch conversation lf - cr/lf
    ... The M$ world has taught virtually everyone that spaces in filenames are no ... folder separator. ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)
  • Re: tar...? Re: [opensuse] Ideas on disk cloning?)
    ... those whose filenames begin with a ... Tar works just fine as long as you use it correctly. ... To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx ... For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx ...
    (SuSE)