I have an assignment to write a shell script that (among other things) when executed without any arguments, the script will perform the following steps:
Update all system packages Install the Nginx software package Configure nginx to automatically start at system boot up. Copy the website documents to the web document root directory. Start the Nginx service.
I have written the tasks that the script is supposed to do, but I don't know how to structure the script so that it does these tasks ONLY when it is run without any arguments.
Whenever I run the script - argument or not, these tasks are executed. I've wrapped the tasks in a function but I don't know how to prompt it to only run when executed without an argument:
#!/bin/bash
# assign variables
ACTION=${1}
Version=1.0.0
function default(){
sudo yum update -y
sudo yum install httpd -y
sudo yum install git -y
sudo amazon-linux-extras install nginx1.12 -y
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
sudo aws s3 cp s3://index.html /usr/share/nginx/html/index.html
}
...
case "$ACTION" in
-h|--help)
display_help
;;
-r|--remove)
script_r_function
;;
-v|--version)
;;
show_version "Version"
;;
default
*)
echo "Usage ${0} {-h|-r|-v}"
exit 1
esac