Ubuntu – How to get a new line at the end of pipe command

bashcommand linels

I want to write a piped sequence of commands which prints out a list of all the subdirectories of the given directory, and printed in one line, following a new line.

I'm having trouble to make the output of the following command to be all at the same line, and then have a new line at the end.

This is my pipe command:

ls -l /share/ |grep ^d |tr -s ' ' |cut -f9 -d' '| tr '\n' ' ' 

And I would like the output to be as:

file1 file3
[user@linux]$

And not (what I actually get:

file1 file3[user@linux]$

Best Answer

What about:

ls -l $/share/ |grep ^d |tr -s ' ' |cut -f9 -d' '| tr '\n' ' ' && echo " "