-1

如何合并以下两个案例脚本?

脚本 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
4

1 回答 1

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}" .
于 2013-04-18T03:52:41.290 回答