如何合并以下两个案例脚本?
脚本1
#!/bin/bash
Ver=0
n="192.168.1.20:/backup/b1"
o1="192.168.1.20:/backup/b2"
User="1234"
echo "n Latrest version"
echo "o1 Previous version n-1"
echo "o2 Previous version n-2"
echo -n "Which version you want to backup [n or p]? "
read Ver
case "$Ver" in
(n|o1|o2) scp $User@${!n} . ;;
(*) echo "UNKNOWN USER"
esac
以上脚本无法正常运行错误
cannot stat `1234@': No such file or directory
脚本2
User=0
av="34567"
ma="4568"
im="5678"
mi="12345"
pr="23456"
echo "Please select av ma ji im pr"
echo -n "First 2 initial of your Name eg: [av ma ji im pr]? "
read User
case "$User" in
(av|ma|pr|mi|im) scp ${!User}@$n . ;;
(*) echo "UNKNOWN USER"
esac
答案 0 :(得分:0)
变量$n
和$Ver
之间的混合,并且未指定$o2
的值。
#!/bin/bash
echo "want to download [yes no]? "
read response
[ "$response" = "yes" ] || exit
n="192.168.1.20:/backup/b1"
o1="192.168.1.20:/backup/b2"
o2="192.168.1.20:/backup/b3"
echo "n Latest version"
echo "o1 Previous version n-1"
echo "o2 Previous version n-2"
echo -n "Which version do you want to backup [n o1 o2]? "
read opt
case "$opt" in
n|o1|o2)
server="${!opt}"
;;
*)
echo "INVALID OPTION" >&2
exit 1
;;
esac
av="34567"
ma="4568"
im="5678"
mi="12345"
pr="23456"
echo -n "Enter your initials [av ma im mi pr]: "
read opt
case "$opt" in
av|ma|im|mi|pr)
user="${!opt}"
;;
*)
echo "UNKNOWN USER" >&2
exit 1
;;
esac
scp "${user}@${server}" .