shell - spliting of output lines into mutliple lines in linux -


my code is:

#!/bin/bash dir="$1"  echo -n "file size:" du="$(du $dir -hab | sort -n -r | tail -1)" printf "%s\n" "echo "$du"" 

it's showing output as:

     file size:echo 0 ./.config/enchant/en_us.dic  

my expected output is:

file size: 0 ./.config/enchant/en_us.dic 

should displayed above. path should in new line 1 tab space.

looks should use this:

#!/bin/bash  dir=$1 printf 'file size: %s\n\t%s\n' $(du "$dir" -hab | sort -n -r | tail -1) 

the lack of quotes around command substitution means word splitting performed. first word in output output on same line "file size: " , second word printed on newline, following tab character.

i've added quotes around $dir inside command substitution, prevent issues word splitting , glob expansion. quotes around assignment aren't necessary (but no harm, can leave them in if want).


Comments