I am still very new to Linux, and I am tasked with writing a bash script that outputs various details inside a menu box. These details include:
Directory owner/permissions,
Number of files in directory,
and Name and size of biggest file
Here is what I have so far:
function show_details(){
read -p "Please enter a path: " path1
cd $path1
ls -ld | > $OUTPUT
ls | wc -l > $OUTPUT
find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head -n 1 > $OUTPUT
display_output 13 25 "Details"
}
It successfully reads the path, as well as outputs name and size of biggest file, but skips the first two. What am I doing wrong that causes the output file to ONLY read the final '> $OUTPUT' with name/biggest file? Any help is appreciated!
>>
instead of>
. However, there are some other things you should look at: i) don't parse the output ofls
. See Greg's Wiki. ii) avoid using CAPS for shell variable names. By convention, global environment variables are capitalized and if yours are as well, that can lead to naming collisions. iii) don't ask your user to type a path, read it at launch (show_details /path
and then use$1
). iiv) *always quote your variables*. – terdon Mar 23 '23 at 16:19