0

everyone. Quick question that is pretty embarrassing. How do you pass a directory as an argument for a bash shell script and how is that written within the actual script? The script is supposed to work in its current directory but if given an argument (another directory), it should work with the given parameters. I've checked around the internet for the last three hours and I keep finding really complicated solutions that just end up confusing me. The question is as follows:

The script should list the disk storage occupied by each immediate subdirectory of a given argument or the current directory (if no argument is given) with the subdirectory names sorted alphabetically. Also, list the name of the subdirectory with the highest disk usage along with its storage size.

Just need help with the first sentence. This is what I have so far. I've done most of the program but the directory issue has me stumped.

#!/bin/bash

ls -xl > file.txt
cut -d ' ' -f 5- file.txt > file2.txt

echo "List in alpha order: "
cat file2.txt
echo 

"Largest dir is: "
du -ab | head -1

Any assistance would greatly be appreciated, please.

4

1 回答 1

2

Parameter substitution.

searchdir="${1:-$PWD}"
于 2013-07-31T05:48:36.550 回答