Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #264777

Re: setting IFS to new line doesn't work while searching?

From Nicolas George <george@nsup.org>
Newsgroups linux.debian.user
Subject Re: setting IFS to new line doesn't work while searching?
Date 2023-12-15 13:50 +0100
Message-ID <HLfND-dKJm-11@gated-at.bofh.it> (permalink)
References <HLfDX-dKFZ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Albretch Mueller (12023-12-15):
> sdir="$(pwd)"
> #fndar=($(IFS=$'\n'; find "$sdir" -type f -printf '%P|%TY-%Tm-%Td
> %TI:%TM|%s\n' | sort --version-sort --reverse))
> #fndar=($(IFS='\n'; find "$sdir" -type f -printf '%P|%TY-%Tm-%Td
> %TI:%TM|%s\n' | sort --version-sort --reverse))
> fndar=($(find "$sdir" -type f -printf '%P|%TY-%Tm-%Td %TI:%TM|%s\n' |
> sort --version-sort --reverse))
> fndarl=${#fndar[@]}
> echo "// __ \$fndarl: |${fndarl}|${fndar[0]}"
> 
> the array construct ($( ... )) is using the space (between the date
> and the time) also to split array elements, but file names and paths
> may contain spaces, so ($( ... )) should have a way to reset its
> parsing metadata, or, do you know of any other way to get each whole
> -printf ... line out of find as part of array elements?

You set IFS in the subshell, but the subshell is doing nothing related
to IFS, it is just calling find and sort. You need to set IFS on the
shell that does the splitting.

Also, note that file names can also contain newlines in general. The
only robust delimiter is the NUL character.

Also, ditch batch. For simple scripts, do standard shell. For complex
scripts and interactive use, zsh rulz:

fndar=(${(f)"$(...)"})
fndar=(${(ps:\0:)"$(...)"})
fndar=(**/*(O))

(I do not think zsh can sort version numbers easily, though.)

Regards,

-- 
  Nicolas George

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

setting IFS to new line doesn't work while searching? Albretch Mueller <lbrtchx@gmail.com> - 2023-12-15 13:40 +0100
  Re: setting IFS to new line doesn't work while searching? Greg Wooledge <greg@wooledge.org> - 2023-12-15 13:50 +0100
    Re: setting IFS to new line doesn't work while searching? Albretch Mueller <lbrtchx@gmail.com> - 2023-12-15 14:10 +0100
  Re: setting IFS to new line doesn't work while searching? Nicolas George <george@nsup.org> - 2023-12-15 13:50 +0100
    Re: setting IFS to new line doesn't work while searching? Greg Wooledge <greg@wooledge.org> - 2023-12-15 14:10 +0100
      Re: setting IFS to new line doesn't work while searching? Nicolas George <george@nsup.org> - 2023-12-15 14:40 +0100
        Re: setting IFS to new line doesn't work while searching? Greg Wooledge <greg@wooledge.org> - 2023-12-15 15:00 +0100
          Re: setting IFS to new line doesn't work while searching? Nicolas George <george@nsup.org> - 2023-12-15 15:10 +0100
          Re: setting IFS to new line doesn't work while searching? David Wright <deblis@lionunicorn.co.uk> - 2023-12-16 06:50 +0100

csiph-web