「セットアップ」スクリプトは、必要な数の異なるスクリプトを作成するために複数回使用されます。
収集する必要がある最大 6 つの変数があります。
変数のコレクションは、
ディレクトリの長さに制限する必要があります(つまり、~/AOKP/vendor/aokp には 3 つ、~/AOKP/Build には 2 つ必要です)。
期待される出力: 正しい数の変数を使用して名前が付けられた子スクリプト (つまり、frameworks_base.sh)
「セットアップ」スクリプトは次のとおりです。
#Create Array
echo "Please enter your Working Directory ROOT (Just the word: For ~/OurROM/ type: OurROM)"
read root
echo "Please Enter the Subequent Directories to the location of your git directory
# -a makes read command to read into an array
read -a gitdir
# get number of elements in the array
elements=${#gitdir[@]}
index=0
while [ "$index" -lt "$elements" ]
do
?????????
echo "Your Directory is ~/$root/${gitdir[0]}/${gitdir[1]}/${gitdir[2]}"
変更が必要な子スクリプト (答える必要はありません... 情報のみ) は次のとおりです。
#!/bin/bash
# This script can be modified to allow for any directory
# Be sure to change all Directory References. References will be proceded in the line above by a *
clear
# * Change if Required
cd ~/OurROM/.scripts
wait
while true; do
clear
# * Change if Required
echo "What would you like to do with .scripts?"
echo "1. Enter Commit Message"
echo "2. Add All Changes"
echo "3. Commit All Changes"
echo "4. Push All Changes"
echo "5. Reset All Changes"
echo "6. Merge Current Directory"
echo "7. REVERT a Commit"
echo "8. "
echo "9. "
echo "10. "
echo ""
echo "Current Commit Message: $commit"
echo ""
echo -n "Enter your choice, or 0 for exit: "
read choice
echo
case $choice in
1)
clear
echo "Please Enter Your Commit Message:"
read commit
echo ""
echo "Commit: '$commit' - has been recorded"
echo ""
read -p "Press [Enter] key to continue..."
;;
2)
clear
echo "Deleting all Hidden files"
find ~/OurROM/ -iname "*.*~" -type f -exec rm {} \;
wait
echo "All HIDDEN files Deleted"
git add --all && git add . && git add -u
wait
echo ""
echo "Changes have been added"
read -p "Press [Enter] key to continue..."
;;
3)
clear
echo "Executing Commit..."
git commit -m "$commit"
wait
echo ""
echo "Message Commited"
echo ""
read -p "Press [Enter] key to continue..."
;;
4)
clear
echo "Pushing your Commit..."
# * Change if Required
git push git@github.com:OurROM/.scripts.git HEAD:jb-mr1
wait
echo ""
echo "$commit - has been pushed to OurROM"
echo ""
read -p "Press [Enter] key to continue..."
;;
5)
clear
git reset --hard HEAD && git clean -f && git checkout origin/jb-mr1
wait
echo ""
echo ".scripts has been RESET"
echo ""
read -p "Press [Enter] key to continue..."
;;
6)
clear
git merge origin/jb-mr1
wait
echo ""
echo "Local Directory is Merged with Online Data"
echo ""
read -p "Press [Enter] key to continue..."
;;
7)
clear
echo ""
echo "Paste the Commit Number you would like to Revert:"
read revert
echo "Commit #: '$revert' - will be reverted. Is this Correct?"
select yn in "Yes" "No"; do
case $yn in
Yes ) git revert $revert; wait; echo "Commit $revert has been reverted"; read -p "Press [Enter] key to continue..."; break;;
No ) break;
esac
done
echo ""
;;
8)
XXXXX REMOVED FOR BREVITY XXXXXXX
*)
echo "That is not a valid choice, try a number from 0 to 10."
;;
esac
done
パート 3:私はあなたからのすべての入力を使用して、私が望むものを手に入れました。次の 2 つの While ステートメントを適切にネストして、データを一度に収集するにはどうすればよいですか? 配列は、ルートのみが変更される可能性があるため、2 つの個別のメニュー項目があります。1つにしたいのですが、ネスティングに失敗します...
8)
clear
echo ""
#Create Array
echo "Please enter your Working Directory ROOT (Just the word: For ~/OurROM/ type: OurROM)"
read root
echo "Please Enter the Subequent Directories to the location of your git directory"
echo "Again, just the words: For ~/OurROM/frameworks/base type: frameworks base"
# -a makes read command to read into an array
read -a gitdir
# get number of elements in the array
elements=${#gitdir[@]}
fullPath="~/${root}"
index=0
while [ "$index" -lt "$elements" ] ; do
# append values from $gitdir until you are done
fullPath="${fullPath}/${gitdir[$index]}"
(( index++ ))
done
;;
9)
clear
echo ""
#Create Array
echo "Please enter your remote github.com repository ROOT (Just the word: For https://github.com/OurROM/ type: OurROM)"
read repo
echo "Please Enter the Subequent Directories to the location of your git repository"
echo "Again, just the words: For https://github.com/OurROM/frameworks/base type: frameworks base"
# -a makes read command to read into an array
read -a repodir
# get number of elements in the array
elements=${#repodir[@]}
repoSave="${repo}/"
index=0
while [ "$index" -lt "$elements" ] ; do
# append values from $gitdir until you are done
repoSave="${repoSave}${repodir[$index]}_"
(( index++ ))
repoPath=${repoSave%?}
done
;;
このようにネストしようとしましたが、最初の出力を 1 つの配列値に切り詰めます。
8)
clear
echo ""
#Create Array
echo "Please enter your Working Directory ROOT (Just the word: For ~/OurROM/ type: OurROM)"
read root
echo "Please enter your remote github.com repository ROOT (Just the word: For https://github.com/OurROM/ type: OurROM)"
read repo
echo "Please Enter the Subequent Directories to the location of your git directory"
echo "Again, just the words: For ~/OurROM/frameworks/base type: frameworks base"
# -a makes read command to read into an array
read -a gitdir
# get number of elements in the array
elements=${#gitdir[@]}
fullPath="~/${root}"
repoSave="${repo}/"
index=0
while [ "$index" -lt "$elements" ] ; do
# append values from $gitdir until you are done
fullPath="${fullPath}/${gitdir[$index]}"
(( index++ ))
index=0
while [ "$index" -lt "$elements" ] ; do
repoSave="${repoSave}${gitdir[$index]}_"
(( index++ ))
repoPath=${repoSave%?}
done
done
;;
どこで私は間違えましたか?