gpt4 book ai didi

linux - shell 脚本 - 当条件检查范围失败时

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:27:59 25 4
gpt4 key购买 nike

我刚刚开始编写 shell 脚本,出于测试目的,我正在尝试创建供我个人使用的脚本。我有一个家庭文件服务器,我有时会与之同步,我正在尝试创建一个交互式脚本,这样我就可以更轻松地完成 mp3 同步任务。

这是我的脚本:

#!/bin/bash
##############################################
############ MP3 SYNC SCRIPT ##############
##############################################
#### REV: 01 20/07/2015
#### Author: Marcio Ribeiro

echo -e "Sincronizar do storage para o note ( escolha 01 ) ou do note para storage ( escolha 02 ): \n 01 Destino final Note: \n 02 Destino final Storage:"
read DESTINO
DESTINO_CK=[0]-[12]

while [ $DESTINO != $DESTINO_CK ] ; do

read -p "Por favor escolha entre 01 ou 02:" DESTINO
done

echo -e "Digite a letra inicial da banda que deseja utilizar na sincronização em CAPS"
read LETRA
LETRACK={AZ}

while [ "$LETRA" != $LETRACK ]; do

read -p "Digite a letra inicial da banda que deseja utilizar na sincronização em CAP:" LETRA
done

LEFT="/storage/Marcio/Mp3/${LETRA}/"
RIGHT="/data/mp3/${LETRA}/"

if [ $DESTINO = "01" ]; then
echo -e "`rsync -rvz ${LEFT} ${RIGHT}`; \n `ls -lha ${RIGHT}`"
else
echo -e "`rsync -rvz ${RIGHT} ${LEFT}`; \n `ls -lha ${LEFT}`"

fi

我已经掌握了基础知识,现在我正试图将用户交互限制在我真正想要的范围内,但我失败了。基本上,在第一个用户提示中,我只想接受 01 或 02 作为输入,在第二个用户提示中,我只想接受一个大写字母。任何人都知道为什么我在如此简单的事情上失败了?

最佳答案

我让它工作了,它不是一个漂亮的代码或最好的逻辑,但它工作:

!/bin/bash
##############################################
############ MP3 SYNC SCRIPT ##############
##############################################
#### REV: 01 20/07/2015
#### Author: Marcio Ribeiro

echo -e "Sincronizar do storage para o note ( escolha 1 ) ou do note para storage ( escolha 2 ): \n 1: Destino final Note \n 2: Destino final Storage"
read DESTINO
until [ "$DESTINO" = "1" ] || [ "$DESTINO" = "2" ];
do
read -p "Por favor escolha entre 1 ou 2:" DESTINO
done
####
echo -e "Digite a letra inicial da banda que deseja utilizar na sincronização em CAPS"
read LETRA
LETRA_CK='[A-Z]'

while [[ "$LETRA" != $LETRA_CK ]];
do
read -p "Digite a letra inicial da banda que deseja utilizar na sincronização em CAPS:" LETRA
done
####
LEFT="/storage/Marcio/Mp3/${LETRA}/"
RIGHT="/data/mp3/${LETRA}/"

if [ $DESTINO = "01" ]; then
echo -e "`rsync -rvz ${LEFT} ${RIGHT}`; \n `ls -lha ${RIGHT}`"
else
echo -e "`rsync -rvz ${RIGHT} ${LEFT}`; \n `ls -lha ${LEFT}`"

fi

欢迎提出任何改进意见。

关于linux - shell 脚本 - 当条件检查范围失败时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31527170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com