0

im running this in bashrc file

function simplefunc () {
    output=$(ls -1 "$HOME")
    linecount=$(${output} | wc -l)

    echo "${linecount}"
    echo "${output}"
}

getting this error

Desktop: command not found
0
Desktop
Documents
Downloads
Music
Pictures
Public
snap
SoftMaker
Templates
venv
Videos

i tried these too

putting "local" before variable or

# linecount=$(output | wc -l)
# echo "$(${output} | wc -l)"
  • 1
    Also [don't parse `ls` output.](https://mywiki.wooledge.org/ParsingLs) Depending on what exactly you want, try e.g. `(cd "$HOME"; printf '%s\n' * ) | nl` – tripleee Aug 19 '21 at 11:19

1 Answers1

0

I think you should change the third line to:

linecount="$(echo "${output}" | wc -l)"
# OR alternatvely:
# linecount="$(wc -l < <(echo "$output"))"
nino
  • 554
  • 2
  • 7
  • 20