I am trying to write a script. In the beginning of the script, I want it to check for internet connectivity and then continue, else the script should stops with message "please check your internet". I am new in bash programming, that why I am not sure that whether "if-then-else" should be used here or "while". Here is my script:
#!/bin/bash if ping -c 1 google.com >& /dev/null then echo "INTERNET IS WORKING..." else echo "PLEASE CHECK YOUR INTERNET!" fi cd $HOME/download pwd
In this script, in case the "if" statement fails, and the script runs the "else" statement, I want this script to stop, instead of going further to "cd $HOME/download" and "pwd".
How can I do this in this script?