Skip to content
Advertisement

In output, echo command printed new line when after printed variable

This is my small bash script code and i want to print the number of files created in the directory :

#! /bin/sh
home_dir=/home/var/foo
Count= ls /$home_dir|wc -l
echo -e "$Count files are existed in the directory $home_dir"
exit 0

My expected output is :

9 files are existed in the directory /home/var/foo

but i got the below output:

9
 files are existed in the directory /home/var/foo

can you help what went wrong in my above code? Also please suggest if this is the correct way to print the number of files in the directory

Advertisement

Answer

This works for me:

Count=$(ls /$xml_dir|wc -l)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement