Nk_cdd
Description
This is a Bash function called nk_cdd that changes the current working directory to the document root directory of a specified domain. It first checks if a domain argument is provided, and if not, it prints an error message and returns. Otherwise, it uses the nk_docroot function to determine the document root directory of the specified domain and stores the result in the docroot variable. It then prints a message indicating the directory it is changing to, and uses the cd command to change to that directory. The || exit ensures that the script exits if the cd command fails for any reason.
Example
[root@cloudvpsserver ~]# nk_cdd nkern.net Changing directory to: /home/nkern/public_html
Code
nk_cdd () { # nk_cdd expects to be receive a domain as an argument. # Print message and exit if one isn't provided. if [ "$1" = "" ]; then echo "you must provide a domain" return 0 fi # In order to change to the docroot we need to know what the docroot is. # simply set the variable docroot to the result of running nk_docroot on the domain provided. docroot="$(nk_docroot "$1")" # Print a message of where we're cding to echo "Changing directory to: $docroot" # And go there. Shell check yells at me if I don't include the || exit. cd "$docroot" || exit }