Re: question about ls
On Wed, Oct 03, 2018 at 12:01:02PM +0000, Virgo Pärna wrote:
> On Thu, 27 Sep 2018 09:14:00 -0400, Greg Wooledge <firstname.lastname@example.org> wrote:
> > But also note that using ls -l gives a completely wrong answer.
> > wooledg:~$ mkdir /tmp/x && cd "$_"
> > wooledg:/tmp/x$ touch $'this\nis\none\nfile'
> > wooledg:/tmp/x$ ls -l | wc -l
> > 5
> What about 'ls -1b | wc -l'?
Not portable, but if you're willing to write scripts that only work with
GNU coreutils installed, maybe an option. You'd probably want to add -A
How about just using one of the bash builtin methods that are presented
on <https://mywiki.wooledge.org/BashFAQ/004>? Not only are they portable
(so long as bash is installed), but they don't require forking external
commands like ls(1) and wc(1) in the first place.