Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making multiple commands appear on the same output line

Tags:

bash

Hi I keep having trouble with this

echo 'Welcome to my first Script'
mkdir myScript
cd myScript
touch doc1 sales.doc.test2.txt outline.doc

echo 'You now have ' ;find . -type f|wc -l;echo 'files in your "myScript" folder'

address="205"
echo -n "Please enter your favourite number:"
read myvar
echo "The number you entered is $myvar"

I'm trying to make the output say "You now have (3) files in your myScript folder" as one line, but it keeps outputting them on 3 seperate lines. I've tried 3 or 4 different codes here (by clicking the similar questions above) but they give me funny errors and this is just my first script, so I understand all the commands I'm using (minus the calculation for files, I had to google that one).

like image 874
user2076851 Avatar asked Dec 15 '22 14:12

user2076851


1 Answers

echo "You now have $(find . -type f|wc -l ) files in your \"myScript\" folder"

Additionally, I'd recommend altering the find to include -maxdepth 1, otherwise you'll recurse...

like image 150
carlpett Avatar answered Jan 05 '23 22:01

carlpett