I'm developing a shell script to sync the particular folder from target to destination path, I need to execute the script like below:
sh deploy.sh deploy staging particular_folder_name
Below is the script which i developed:
function deploy() {
staging
}
function staging() {
ENTITY_NAME="$1"
echo "deployment here"
ENTITY_PATH=`ls -ld /u01/home/${USER}/testing_vela/subject-areas/entites/staging-modules/${ENTITY_NAME}`
echo $ENTITY_PATH
DEPLOYMENT_FOLDER=`echo $ENTITY_PATH|rev|awk -v FS='/' '{print $1}'|rev`
echo $DEPLOYMENT_FOLDER
SOURCE_PATH='/u01/home/${USER}/testing_vela/deploy/subject-areas/modules'
DESTINATION_PATH='/u02/home/${USER}/testing_vela/subject-areas/entites/staging-modules'
if [ "${ENTITY_NAME}" == "${DEPLOYMENT_FOLDER}" ]
then
echo "folder is exist"
rsync -avzh ${SOURCE_PATH}/${ENTITY_NAME} ${DESTINATION_PATH}/${ENTITY_NAME}
else
echo "folder does not exist"
fi
}
case $1 in
deploy) "$@";
staging) "$@";
esac
Can someone help me to correct, if I am doing anything wrong in the above script? I am facing the below error whenever I execute the script.
ERROR:
sh deploy.sh deploy staging contract
deploy.sh: line 87: syntax error near unexpected token `)'
deploy.sh: line 87: `staging) "$@";'
CodePudding user response:
The syntax for a case
statement requires 2 semi-colons to terminate the commands of a case:
case $1 in
deploy) "$@";;
staging) "$@";;
esac
CodePudding user response:
If it still throws error , put the 2 semi-colons on next line like below :
case $1 in
deploy) "$@"
;;
staging) "$@"
;;
esac