Creation of several teams in one output line

Hi i have problems 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 am trying to conclude: "You now have (3) files in your myScript folder" as one line, but it continues to display them on 3 separate lines. I tried 3 or 4 different codes here (clicking on similar questions above), but they bring me ridiculous errors, and this is just my first script, so I understand all the commands that I use (minus the calculation for files, I had to do it on google).

+4
source share
4 answers

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

Also, I would recommend changing find to include -maxdepth 1 , otherwise you restart ...

+7
source

They are on separate lines because echo and wc print new lines.

One of the methods:

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

Here we get rid of the extra line echo newline, because we use one echo to manage them all. We are freed from the line wc newline, because with this substitution, the output of wc broken into words, and these words are passed to echo as separate arguments; word separators are lost (echo uses space to separate its arguments at the output).

+3
source

Use the no-new-line -n switch and the echo result of your find :

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

Use the printf command:

 printf 'You now have %d files in your "myScript" folder' $( find . -type f | wc -l ) 

(A slight deviation from other answers using command substitution built into the string.)

0
source

All Articles