Rumen Hristov Rumen Hristov - 9 months ago 44
Bash Question

concatenate grep output to an echo statement in UNIX

I am trying to output the number of directories in a given path on a SINGLE line. My desire is to output this:

X-many directories

Currently, with my bash sript, I get this:



Here's my code:


ls -l $ARGUMENT | egrep -c '^drwx'; echo -n "directories"

How can I fix my output? Thanks


I suggest

 echo "$(ls -l "$ARGUMENT" | egrep -c '^drwx') directories"

This uses the shell's feature of final newline removal for command substitution.