嘿伙计们,我在第二个嵌套的 else 周围遇到了一个错误,我认为这与将文件移动到名称中带有空格的文件夹有关,但我不确定,所以我尝试添加另一个嵌套的 if这将允许我重命名,但它也会引发关于格式化的错误?
我认为真正的问题是我嵌套 ifs 错误?
错误
/bin/y2m: line 16: syntax error near unexpected token `then'
/bin/y2m: line 16: ` if[ -z "$newname" ]; then'
代码
#!/bin/bash
address=$1
newname=$2
regex='v=(.*)'
if [[ $address =~ $regex ]]; then
video_id=${BASH_REMATCH[1]}
video_id=$(echo $video_id | cut -d'&' -f1)
if[ -z "$newname" ]; then
video_title="$newname"
else
video_title="$(youtube-dl --get-title $address)"
fi
youtube-dl -o "$video_title".flv $address
ffmpeg -i "$video_title".flv -acodec libmp3lame -ac 2 -ab 256k -vn -y "$video_title".mp3
if [ -d "/media/SDHC CARD/Music/y2m" ]; then
mv "$video_title".mp3 "/media/SDHC CARD/Music/y2m"
echo "Moving to Phone Card"
else
mv "$video_title".mp3 ~/Music
echo "Moving to Music Folder"
fi
rm "$video_title".flv
else
echo "Sorry but you seemed to broken the interwebs."
fi