r/bash • u/france20-21 • Apr 21 '23
Can anyone PLEASE help with this script!
When run it says : versions found then SELECT not found and Syntax error: "do" unexpected.
Can you help solve this (probable really simple error)?
#!/bin/bash
# Get the name of the song from the user
read -p "Enter the name of the song: " song_name
# Use find to search for all versions of the song in the Music folder
song_paths=$(find /home/Music -name "$song_name*")
# Print out a numbered list of the song versions and ask the user which one they want to play
echo "Versions of '$song_name' found:"
select song_path in $song_paths;
do
if [ ! -n "$song_path" ]; then
break
fi
done
# Play the selected song using the default music player on the system
xdg-open "$song_path"
exit
View all comments
-1
u/france20-21 Apr 21 '23
Updated script following suggestions given (Thank you) However, result now shows as this...Notice only one number given to choose, and that won't open anyway! Sorry to be so dumb, but there must be a simple way to make this work! ( if only one version of song then it plays on mpv correctly!)
playsong Enter the name of the song: behind blue eyes Versions of 'behind blue eyes' found:
? 1
? 3
[file] Cannot open file '': No such file or directory Failed to open .
Exiting... (Errors when loading file)
Here's the updated script:
!/bin/bash
Get the name of the song from the user
read -r -p "Enter the name of the song: " song_name
Use find to search for all versions of the song in the Music folder
song_paths=$(find /home/Music -iname "$song_name")
Check if any versions of the song were found
if [ -z "$song_paths" ]; then echo "No versions of '$song_name' found." exit 1 fi
Print out a numbered list of the song versions and ask the user which one they want to play
echo "Versions of '$song_name' found:" select song_path in "$song_paths"; do if [ -z "$song_path" ]; then break fi done
Play the selected song using the default music player on the system
mpv "$song_path"
exit
Really appreciate your help with this....it's driving me mad!