2015-12-05 56 views
1

這是我的問題:adb腳本推送錯誤

我剛剛買了我的Nexus 5X,我很滿意它。但我在Mac上,我喜歡命令行,所以我決定寫一個腳本來送我的音樂在幾個步驟:

1 - 對一個文件寫的歌的列表發送

2 - 在文件上寫入已經在我的Nexus'音樂文件夾中的所有歌曲

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文件,路徑的歌曲與非轉義空間寫的事實,這個問題...我會考慮它

回答

0

嘗試

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

,而不是你自己的線

+0

我不得不把絕對路徑進行修改,但一旦我這樣做,它的工作!謝謝 ! –