Bash 脚本中的adb推送错误
我的问题是: 我刚买了我的Nexus 5X,我很满意。但是我在mac上,我喜欢命令行,所以我决定编写一个脚本,分几个步骤发送我的音乐: 1-在文件中写入要发送的歌曲列表 2-将Nexus音乐文件夹中已有的所有歌曲写入文件 3-浏览文件中有文件要发送的每一行,检查这一行是否是手机上的歌曲,如果不是,则发送 我无法完成最后一步,它会为循环的每个步骤打印adb帮助页面 以下是脚本:Bash 脚本中的adb推送错误,bash,adb,Bash,Adb,我的问题是: 我刚买了我的Nexus 5X,我很满意。但是我在mac上,我喜欢命令行,所以我决定编写一个脚本,分几个步骤发送我的音乐: 1-在文件中写入要发送的歌曲列表 2-将Nexus音乐文件夹中已有的所有歌曲写入文件 3-浏览文件中有文件要发送的每一行,检查这一行是否是手机上的歌曲,如果不是,则发送 我无法完成最后一步,它会为循环的每个步骤打印adb帮助页面 以下是脚本: #!/bin/bash ##################### ##### FUNCTIONS ##### ##
#!/bin/bash
#####################
##### FUNCTIONS #####
#####################
usage()
{
echo "usage: sendMusicNexus.sh"
}
error_exit()
{
# Display error message and exit
echo "${0}: ${1:-"Unknown Error"}" 1>&2
exit 1
}
#####################
######## Main #######
#####################
# Check if the device is connected
if [ `adb devices | wc -l` -ne 3 ]; then
error_exit "Device not found"
fi
# List all the files to send, sort and uniq (Artist/Album/*.mp3)
cat ~/.mpd/playlists/*.m3u > allsongstosend
sort -o allsongstosend allsongstosend ; uniq allsongstosend allsongstosenduniq
rm allsongstosend
# List all the files in the Music folder of the Nexus (name.mp3)
adb shell ls -R /storage/self/primary/Music | grep mp3 > allsongsthere
# Loop through the files to send
while read SONG
do
# Keep the name under the pattern song.mp3
temp=$(echo $SONG | rev | cut -d / -f 1 | rev)
# Look for the file in the list of what's in the phone
grep -q "$temp" allsongsthere
# If it's not, push it
if [ $? -ne 0 ]; then
adb push ~/Music/iTunes/iTunes Media/Music/${SONG} /storage/self/primary/Music/${SONG}
fi
done < allsongstosenduniq
#/bin/bash
#####################
#####功能#####
#####################
用法()
{
echo“用法:sendMusicNexus.sh”
}
错误_exit()
{
#显示错误消息并退出
回显“${0}:${1:-“未知错误”}”1>&2
出口1
}
#####################
########主要#######
#####################
#检查设备是否已连接
如果[`adb设备| wc-l`-ne 3];然后
错误\u退出“未找到设备”
fi
#列出所有要发送、排序和uniq的文件(Artist/Album/*.mp3)
cat~/.mpd/playlists/*.m3u>allsongstosend
排序-o allsongstosend allsongstosend;uniq allsongstosend allsongstosenduniq
奥尔松斯托森酒店
#列出Nexus(name.mp3)音乐文件夹中的所有文件
adb shell ls-R/storage/self/primary/Music | grep mp3>所有歌曲
#循环浏览要发送的文件
一边读着歌
做
#将名称保留在模式song.mp3下
温度=$(回声$SONG |版本|剪切-d/-f 1 |版本)
#在手机中的内容列表中查找该文件
grep-q“$temp”所有歌曲
#如果不是,推它
如果[$?-ne 0];然后
adb推送~/Music/iTunes/iTunes媒体/Music/${SONG}/storage/self/primary/Music/${SONG}
fi
完成
我怎样才能让它工作
谢谢
编辑——问题似乎来自这样一个事实:在m3u文件中,歌曲的路径是用非转义空间写入的。。。我会调查的试试看
adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"
不要使用自己的线路试试看
adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"
而不是你自己的线我不得不通过放置绝对路径来修改它,但一旦我这样做了,它就工作了!谢谢我必须通过放置绝对路径来修改它,但一旦我这样做了,它就工作了!谢谢