일련의 디렉토리를 만들고 프로젝트를 선택한 디렉토리에 복제하는 bash 스크립트를 작성했습니다.
이를 cd
위해 각 디렉토리 ( project 1
및 project 2
)로 이동해야하지만 스크립트는 cd
두 번째 디렉토리로 이동하지 않으며 명령을 실행 하지 않습니다 .
대신 디렉토리 cd
에서 복제 후 중지됩니다 project2
. cd_project1
다음 코드에서 함수를 호출하지 않는 이유는 무엇 입니까?
#!/bin/bash
#Get the current user name
function my_user_name() {
current_user=$USER
echo " Current user is $current_user"
}
#Creating useful directories
function create_useful_directories() {
if [[ ! -d "$scratch" ]]; then
echo "creating relevant directory"
mkdir -p /home/"$current_user"/Downloads/scratch/"$current_user"/project1/project2
else
echo "scratch directory already exists"
:
fi
}
#Going to project2 and cloning
function cd_project2() {
cd /home/"$current_user"/Downloads/scratch/"$current_user"/project1/project2 &&
git clone https://username@bitbucket.org/teamsinspace/documentation-tests.git
exec bash
}
#Going to project1 directory and cloning
function cd_project1() {
cd /home/"$current_user"/Downloads/scratch/"$current_user"/project1/ &&
git clone https://username@bitbucket.org/teamsinspace/documentation-tests.git
exec bash
}
#Running the functions
function main() {
my_user_name
create_useful_directories
cd_project2
cd_project1
}
main
터미널 출력 :
~/Downloads$. ./bash_install_script.sh
Current user is mihi
creating relevant directory
Cloning into 'documentation-tests'...
remote: Counting objects: 125, done.
remote: Compressing objects: 100% (115/115), done.
remote: Total 125 (delta 59), reused 0 (delta 0)
Receiving objects: 100% (125/125), 33.61 KiB | 362.00 KiB/s, done.
Resolving deltas: 100% (59/59), done.
~/Downloads/scratch/mihi/project1/project2$
exec bash
.