#sets dir name
echo "What is the name of the target?"
read targetName
#changes dir to desktop
mkdir -p ../Desktop/Notes
cd ../Desktop/Notes
#make working directory
mkdir $targetName
cd $targetName
mkdir "IPs" "SubDomains" "Screenshots" "NmapScans" "Notes"
我一直試圖用 bash 中的簡單回圈來解決我的問題。我有以下腳本,我想向用戶詢問“targetName”以創建一些目錄。創建目錄后,我希望腳本詢問用戶是否要創建另一個目標,如果是/是回圈回傳,如果否則退出。我意識到這是一個相當簡單的問題,一般來說是 bash 和編程的新手,如果我自己創建問題,我會作業得最好。我 99% 確定我需要一個 if 回圈。我只是不確定如何正確分解它。提前致謝!
uj5u.com熱心網友回復:
看看是否對你有幫助:
while true
do
printf 'What is the name of the target? '
IFS= read -r targetName
# sanity checks:
# - no empty string
# - no '/'
[ ${#targetName} -eq 0 ] || [[ ${targetName} == */* ]] && continue
# for now, just print what you'll be doing
printf 'mkdir -p \\\n'
printf ' %q \\\n' ~/Desktop/Notes/"$targetName"/{IPs,SubDomains,Screenshots,NmapScans,Notes}
printf 'Do you wish to create an other target?[y/n] '
read -n 1 yesno
echo
case "$yesno" in
[Yy]) continue;;
*) break;;
esac
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/356293.html
