Re: The ls command
On Fri, Oct 31, 2025 at 6:15 AM Nicolas George <george@nsup.org> wrote:
> Greg Wooledge (HE12025-10-31):
> > On Thu, Oct 30, 2025 at 21:51:16 -0700, Michael Paoli wrote:
> > > $ ls ... | sort
> > > may give results different than, e.g. ls -1 or what one might
> > > otherwise be expecting/anticipating,
> > You'd have to work pretty hard for that to be true. Can you come up
> > with an actual example?
Not hard at all, e.g. have one or more newlines within the file name.
I earlier did so. I'll add a wee bit more context, perhaps that will
help clarify:
$ PS2=''; >'three
line
file'; PS2='> '
On Thu, Oct 30, 2025 at 9:51 PM Michael Paoli
<michael.paoli@berkeley.edu> wrote:
> On Thu, Oct 30, 2025 at 2:17 PM Van Snyder <van.snyder@sbcglobal.net> wrote:
> > ls lists files one-per-line if its output is piped other than stdout
> Not always.
> How 'bout three lines for one file:
> $ ls | cat
> three
> line
> file
> $ ls
> 'three'$'\n''line'$'\n''file'
> $ man ls | col -b | expand | grep -e '-1.*one'
> -1 list one file per line
> $ ls -1 | cat
> three
> line
> file
> $
> documentation. Even though the documentation is excellent and
> typically fully correct, it's not always 100.0000...% correct.
> And similarly,
> $ ls ... | sort
> may give results different than, e.g. ls -1 or what one might
> otherwise be expecting/anticipating,
> e.g. in same directory again with same contents:
> $ ls | sort
> file
> line
> three
> $
Reply to: