以下、私はif
ステートメントとcase
ステートメントを使用して、rsyncで繰り返し入力するのを簡単にするために、以下の私の議論の順序を整理します。以下のif
ブロックのcase
ステートメントは賢明でしょうか?もしそうなら、どうですか?Bash:if対case
#!/bin/bash
rsync="rsync -vrtzhP --delete"
localmus=" /cygdrive/c/Users/user/Music/Zune/"
remotemus=" 10.252.252.254::Zune/"
localcal=" /cygdrive/c/Users/user/calibre/"
remotecal=" 10.252.252.254::calibre/"
dry=" -n"
if [ $1 == "zune" ] && [ $2 == "tohere" ]
then
toex=$rsync$remotemus$localmus
fi
if [ $1 == "zune" ] && [ $2 == "tothere" ]
then
toex=$rsync$localmus$remotemus
fi
if [ $1 == "calibre" ] && [ $2 == "tohere" ]
then
toex=$rsync$remotecal$localcal
fi
if [ $1 == "calibre" ] && [ $2 == "tothere" ]
then
toex=$rsync$localcal$remotecal
fi
if [[ $3 == "dry" ]]
then
toex=$toex$dry
fi
echo
echo $toex
echo
echo "Execute? y/n: "
read answer
case $answer in
y)
eval $toex
;;
n)
echo NO!
;;
esac
はそれに切り替えるために$ 1、$ 2連結Youcould。 – eckes