脚本中的adb推送错误

时间:2015-12-05 18:33:25

标签: bash adb

这是我的问题:

我刚买了我的Nexus 5X,我很满意。但是我在Mac上,我喜欢命令行,所以我决定写一个脚本来发送我的音乐几步:

1 - 在文件上写下要发送的歌曲列表

2 - 在文件上写下Nexus'Music文件夹中已有的所有歌曲

3 - 浏览文件中要发送文件的每一行,检查这一行是否是手机上的歌曲,如果没有发送。

我无法完成最后一步,它会为循环的每一步打印adb帮助页面。

这是脚本:

#!/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

我怎样才能让它发挥作用?

谢谢!

编辑 - 似乎问题来自这样一个事实:在m3u文件中,歌曲的路径是用非转义空间写的......我会调查它

1 个答案:

答案 0 :(得分:0)

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

而不是你自己的行