我正在尝试创建一个bash脚本来捕获运行它的用户的输入。输入将沿目标和源目录的名称行。源目录的布局为每小时。#,每日。#和每月。#。输入将像hourly.33一样捕获并更改到该目录以将该文件夹的所有内容复制到目标。总共有2个目的地可供选择,但有55个不同的来源。我没有使用以下内容包裹我的头:
#!/bin/bash
### Modify below this ###
srv1=/home/minecraft/test/rr1server2
srv2=/home/minecraft/test/rr2server2
srv3=/home/minecraft/test/rrlobby2
### DO NOT MODIFY BELOW THIS ###
while true; do
read -p "Are you sure you want to start the rollback?:" yn
case $yn in
[Yy]* )
while true; do
read -p "Which server? 1, 2 or 3:" srv
case $srv in
[1]* )
while true; do
read -p "Which backup? Input only hourly.#, daily.# or monthly.#:" rollback
cd $rollback
cp -Rp * $srv1
echo "Rollback Complete!"; exit;;
[2]* )
while true; do
read -p "Which backup? Input only hourly.#, daily.# or monthly.#:" rollback
cd $rollback
cp -Rp * $srv2
echo "Rollback Complete!"; exit;;
esac
done
[3]* )
while true; do
read -p "Which backup? Input only hourly.#, daily.# or monthly.#:" rollback
cd $rollback
cp -Rp * $srv3
echo "Rollback Complete!"; exit;;
esac
done
exit;;
esac
done
exit;;
esac
done
我得到以下
minecraft@cronus:~/test$ ./rollback.sh
./rollback.sh: line 21: syntax error near unexpected token `;;'
./rollback.sh: line 21: ` echo "Rollback Complete!"; exit;;'
答案 0 :(得分:2)
我认为您已经发现,使用该程序的当前结构,调试变得越来越困难。
因此,我认为现在开始使用功能是不可思议的。 这是你的程序吐出的功能,几乎所有的程序仍然是你的代码。
现在我担心新功能,但调试更容易:-)
(事实上,我发现了一些)
#!/bin/bash
### Modify below this ###
srv1="/home/minecraft/test/rr1server2"
srv2="/home/minecraft/test/rr2server2"
srv3="/home/minecraft/test/rrlobby2"
### DO NOT MODIFY BELOW THIS ###
RollBack()
{
while :
do
read -p "Which backup? Input only hourly.#, daily.# or monthly.#:" rollback
cd "$rollback"
cp -Rp * "$1"
echo "Rollback Complete!"
done
}
WhichServer()
{
read -p "Which server? 1, 2 or 3:" srv
case "$srv" in
[1]* ) RollBack "$srv1" ;;
[2]* ) RollBack "$srv2" ;;
[3]* ) RollBack "$srv3" ;;
esac
}
while :
do
read -p "Are you sure you want to start the rollback?:" yn
case "$yn" in
[Yy]* ) while true; do WhichServer; done ;;
esac
done