Here is my problem:
I just bought my Nexus 5X and I'm very happy with it. But I'm on mac and I like the command line, so I decided to write a script to send my music in a few steps:
1 - write on a file a list of the songs to send
2 - write on a file all the songs that are already on my Nexus' Music folder
3 - go through each line of the file where there are the files to send, check if this line is a song on the phone or not, and if not send it.
And I can't have the last step to work, it prints the adb help page for each step of the loop.
Here is the script :
#!/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
How can I get this to work ?
Thanks !
Edit -- It seems that the problem come from the fact that in the m3u files, the path to the songs is written with non-escaped space... I'll look into it
try
adb push "~/Music/iTunes/iTunes Media/Music/${SONG}" "/storage/self/primary/Music/${SONG}"
instead of your own line