I want to use the
echo command to show this output:
10 item in File
but seems that the below command does not work:
echo "$('cat file.txt | wc -l ') items in File"
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The correct command is:
echo "$(wc -l < file.txt) items in File"
Note the quotes, for example, by doing:
$('du / -h | sort -h')
You are telling to the shell "hey, execute 'du / -h | sort -h'", and bash will reply, "oh no, I don't know what is 'du / -h | sort -h' is". I am a not 100% sure but I think that when you quote something you escape special characters, like '|'.
The solution for the above example is remove the quotes.
$(du / -h | sort -h)
The output of your command already tells what is going on:
zsh: command not found: cat file.txt | wc -l