脚本中的adb推送错误

adb push error in script

这是我的问题:

我刚买了 Nexus 5X,我对它非常满意。但是我在 mac 并且我喜欢命令行,所以我决定编写一个脚本来通过几个步骤发送我的音乐:

1 - 在文件中写入要发送的歌曲列表

2 - 将 Nexus 音乐文件夹中已有的所有歌曲写入文件

3 - 遍历要发送的文件的每一行,检查这一行是否是 phone 上的歌曲,如果不是,则发送它。

而且我无法执行最后一步,它会为循环的每个步骤打印 adb 帮助页面。

这是脚本:

#!/bin/bash


#####################
##### FUNCTIONS #####
#####################

usage()
{
    echo "usage: sendMusicNexus.sh"
}

error_exit() 
{
    # Display error message and exit
    echo "[=10=]: ${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

我怎样才能让它工作?

谢谢!

编辑 -- 好像问题出在m3u文件中,歌曲的路径是用非转义写的space...我会研究一下

尝试

adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"

而不是你自己的线路