So I have written a bashscript.sh
file to check if a directory project1_repo
is empty after cloning a project.
I have written four different functions to authenticate it but all the time I get command not found
error. I have checked multiple times if there is a syntax error
but in vain. Could someone please help me out? Thanks.
EDIT: Previously due to a typo project1_install_dir
was called colsim1_install_dir
but the edited version is correct.
#!/bin/bash
#path to install project1
function project1_install_dir() {
while true;
do
read -p "Enter FULL folder path where you want to install project1:" fullpath
echo "you have enterd $fullpath. Please press 'y' to confirm and 'n' to enter again"
read -p "Continue? (Y/N): " confirm
if [[ $confirm =~ ^([yY][eE][sS]|[yY])$ ]]; then
break
else
continue
fi
done
}
#clone project1
function clone_project1_repo() {
git clone example git .
}
# four functions to Check whether cloning is successful
# function 1
function success_of_cloning_of_project1_repo3() {
if find $fullpath/project1/project1_repo -mindepth 1 | read; then
echo "dir not empty"
else
echo "dir empty"
fi
}
# function 2
function success_of_cloning_of_project_repo2() {
DIR="$fullpath/project1/project1_repo"
if [ -n "$(ls -A $DIR)" ]; then
echo "Take action $DIR is not Empty"
else
echo "$DIR is Empty"
fi
}
# function 3
function success_of_cloning_of_project_repo1() {
if [ -d $fullpath/project1/project1_repo ]; then
[ -n "$(ls -A $fullpath/project1/project1_repo)" ] && echo "Not Empty" || echo "Empty"
else
:
fi
}
# function 4
function success_of_cloning_of_project_repo() {
while true;
do
if [ -n "$(ls -A $fullpath/project1/project1_repo)" ]; then
echo "cloning of project1_repo is successful"
break
else
echo "cloning of project1_repo is NOT successful."
continue
fi
done
}
#calling the functions
function main() {
project1_install_dir
success_of_cloning_of_project1_repo3
success_of_cloning_of_project1_repo2
success_of_cloning_of_project1_repo1
success_of_cloning_of_project1_repo
}
main
Terminal output:
jen@ex343:tdk/jen$ source bash_file_test.sh
Enter FULL folder path where you want to install project1:/tdk/jen
you have enterd /tdk/jen. Please press 'y' to confirm and 'n' to enter again
Continue? (Y/N): y
You have chosen yes
-bash: success_of_cloning_of_project1_repo3: command not found
-bash: success_of_cloning_of_project1_repo2: command not found
-bash: success_of_cloning_of_project1_repo1: command not found
-bash: success_of_cloning_of_project1_repo: command not found
Pasting your code into https://www.shellcheck.net/ reports:
You can follow the suggestion to use
"$fullpath"
and any other recommendations in comments above. After fixing current errors ShellCheck reports, it may then report additional errors when you run it again.