How do i use the if/else conditional statements in bash shell scripts?
-
Also see: How do i use the if conditional statements in bash shell scripts?
The structure of the if/else conditional statements is as follows:
if condition; then action else action fi
Go back to the How do i use the if conditional statements in bash shell scripts? article. We will add the else condition to this script; to work out the disk usage of a directory. Note: You need read permissions to the directory you use in this example.
if [ $# -lt 1 ];then echo "You must specify a directory name" echo "Usage: $0 <directoryname>" exit 1 else du -sh $1 fi
Running the script.
$ ./dirsize.sh /home/trainer/bin 26M /home/trainer/bin
© Lightnetics 2024