Re: IFS=$'\n'

Liste des GroupesRevenir à cu shell 
Sujet : Re: IFS=$'\n'
De : nn.throttle (at) *nospam* xoxy.net (Helmut Waitzmann)
Groupes : comp.unix.shell
Date : 13. Aug 2024, 13:14:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <83a5hgad4i.fsf@helmutwaitzmann.news.arcor.de>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 Lawrence D'Oliveiro <ldo@nz.invalid>:
However, if you change this to >
>
    IFS=$'\n'
>
then this can make things much more convenient (provided you can be sure there are no newlines in your file names). For example, I can do >
>
    ls -lt $(find . -type f -iname \*fred\*)
>
to search for all filenames containing “fred” in the hierarchy rooted at the current directory, and display them in reverse chronological order. >
 Even if one is sure there are no linefeeds in the file names a  cautious design could do    (
     IFS=$'\n' &&
     ls -lt -- $(find . -name \*$'\n'\* ! -prune -o \
     ! -name \*$'\n'\* -iname \*fred\* -type f -print
     )
   )
 That will work if there are really no linefeeds in file names.   And if there inadvertently were any linefeeds in file names it  would at least not list file names that don't match the  “\*fred\*“ file name pattern.  But – according to the new POSIX standard  (<https://pubs.opengroup.org/onlinepubs/9799919799/utilities/find.html#top>  and  <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/xargs.html#top>) –  one can use “xargs“ to get rid of any linefeed trouble at all:    find . -iname \*fred\* -type f -print0 |
   xargs -0 -r -x -- ls -lt --
 That will work with any file names, even those containing a  linefeed character.
Date Sujet#  Auteur
13 Aug 24 * IFS=$'\n'8Lawrence D'Oliveiro
13 Aug 24 `* Re: IFS=$'\n'7Helmut Waitzmann
13 Aug 24  `* Re: IFS=$'\n'6Ralf Damaschke
14 Aug 24   +- Re: IFS=$'\n'1Lawrence D'Oliveiro
14 Aug 24   `* Re: IFS=$'\n'4Christian Weisgerber
15 Aug 24    +* Re: IFS=$'\n'2Ralf Damaschke
15 Aug 24    i`- Re: IFS=$'\n'1Ed Morton
15 Aug 24    `- xargs -x (was: IFS=$'\n')1Geoff Clare

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal