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) "$@";'
.shsuffix on your shell script: talisman.org/~erlkonig/documents/…echo >&2 'folder does not exist'. But it seems very strange to emit that error in response to a fragile parsing ofls. If you are going to confirm the existence of a directory, usetest -d.basenamerather thanrev|awk|rev. Also, in awk you can get the last field with$NF, so you don't need therev.${ENTITY_PATH##*/}to get the last component of the path.SOURCE_PATH='/u01/home/${USER}/...'won't work; use double-quotes instead. shellcheck.net will spot this and a number of other problems in the script.