0

I have created a small alias that will list files and display the number of files at the end. However I fail in passing additional input to the alias.

alias ll='ls -lFh --group-directories-first $@; numFiles=`ls -l $@ | wc -l`; echo $numFiles" files"'  

while ll works as expected ll /home does not list the content of the home directory

select
  • 2,513
  • 2
  • 25
  • 36
  • 1
    There is no simple way for aliases. Use a function. `ll() { yourCodeHere; }`. You *could* use `alias="bash -c ..."`but that's longer and less efficient than a function. – Socowi Jan 31 '19 at 19:01

1 Answers1

0

Thanks Socowi with a function it works

ll() {
  ls -lFh --group-directories-first $@;
  numFiles=`ls -l "$@" | wc -l`;
  echo $numFiles" files"
}
select
  • 2,513
  • 2
  • 25
  • 36
  • 1
    The usage of `$@` makes only sense in double quotes: `"$@"`. Otherwise it is the same as `$*`and word split happens. Same for `${NAME[@]}` – Wiimm Feb 01 '19 at 07:56
  • Thanks, I edited the post. – select Feb 01 '19 at 19:07
  • And I edited the first occurrence of $@. Because of 6 chars rules, I added trash and can't remove this trash. – Wiimm Feb 01 '19 at 19:16