I have a BASH scripting question. I'd like the mention that I am new to BASH scripting; however, I am not new to programming. I am developing a simple BASH script to watch a given compass project. My script is shown below.
I would like to allow a user to optionally enter a custom path or use the default http_path
value. I'm not sure how to set the path
variable equal to the http_path
variable where my default Apache directory is located using my current script. If any one has better suggestions and/or resources for learning how to write BASH scripts, please share!
Note: I have searched this site, Google, and stackoverflow for an answer. If you find one with a solution to my issue, please let me know!
#!/bin/bash
# This script will watch a given compass project
http_path=/var/www/
echo -n "Enter in a new path and press. To use the default path $http_path press [ENTER] twice"
while read path; do
if [ -z "${path}" ]; then
clear
# these two lines enable the script to work if I do not
# I do not prompt for default path. It's been tested and works
# echo "That was empty, do it again!"
# echo -n "Enter in a compass project directory and press [ENTER]"
echo "Are you sure you would like to use the default path? Press [ENTER] to continue..."
$path=$http_path
else
echo "Checking now..."
break
fi
done
echo -n "Enter in a project to watch and prss [ENTER]"
while read project; do
if [ -z "${project}" ]; then
clear
echo "That was empty, do it again!"
echo -n "Enter in a compass project name and press [ENTER]"
else
echo "Checking now..."
break
fi
done
echo "Watching" $project "project in directory" $path
echo "To exit project press Command/Control + C"
cd $path
compass watch $project
See problem solution here