나는 인수 세트를 취하는 bash 스크립트를 작성했고, 다른 것들을 기반으로합니다.명령으로 인식되지 않음 - bash
./acorn.sh aisiscore install
을하지만 첫 번째 인수가 reconized되지 없다는 내 오류 메시지에 가서 내가 aisiscore이나 자산을 사용해야한다 :이 경우에 나는 말을하려합니다. 나는 철자법을 검사하고 나는 정확하다, 나는 논쟁을 제대로 검사하지 않는가?
#!/bin/bash
set -e
function checkCoreArgument(){
if [[ $1 == 'aisiscore' ]]
then
checkAisisArguments
elif [[ $1 == 'assets' || $1 == 'asset' ]]
then
checkAssetsArguments
else
echo "$1 is not recognized. Please try aisiscore or assets"
fi
}
function checkAisisArguments(){
if [[ $2 == 'install' ]]
then
installAisisCore
elif [[ $2 == 'update' ]]
then
updateAisisCore
elif [[ $2 == 'components' ]]
then
callCompomnentsCheck
else
echo "$2 is not recognized. Please try install or update."
fi
}
function checkAssetsArguments(){
if [[ $2 == 'install' ]]
then
installAssets
elif [[ $2 == 'update' ]]
then
updateAisisCore
else
echo "$2 is not recognized. Please use install or update."
fi
}
function installAisisCore(){
cd scripts/install/
chmod +x InstallAisisCore.sh
sudo InstallAisisCore.sh
}
function updateAisisCore(){
cd scripts/update/
chmod +x UpdateAisisCore.sh
sudo UpdateAisisCore.sh
}
function installAssets(){
cd scripts/install/
chmod +x InstallAssets.sh
sudo InstallAssets.sh
}
function updateAisisCore(){
cd scripts/update/
chmod +x UpdateAssets.sh
sudo UpdateAssets.sh
}
function callCompomnentsCheck(){
cd scripts/install
chmod +x InstallComponents.sh
sudo ./InstallComponents.sh
}
###### =============================== [ Application run ] =============== ######
checkCoreArgument #run the app!
읽기 쉽도록 아래로 내려갔습니다. 당신은 그들이 당신이 그들을 통과해야 스크립트의 인수를 구문 분석하려면
스와 ggestion :'case ['$ [-gt 0]]'루프를'case' 문과 함께 사용하고 각 경우에 대해'shift'를 사용하여 모든 인수를 반복하고 변수를 설정하면 어떤 작업을 추적해야합니까? 수행해야합니다 (그리고 인수에서 필요한 다른 데이터). 그런 다음 실제로 변수를 제어하는'if' 블록 안에 태스크를 수행하는 코드를 넣으십시오. –