I’m working on a script at the moment, and I keep running into a problem when the script will stop and go to the background immediately after starting. I’m pretty sure that this is occurring because the URL is not escaped after I enter it, but I’m not sure how to go about making it, so it will be escaped as soon as I enter it.
I have pasted the code the below as well as what happens when I try to run it. Once again, I really just need help with getting the URL to escape properly upon entry.
#!/bin/bash
#
url=$1
if [ "$url" = "" ]; then
echo "D: you did not supply a url!"
exit
fi
echo "Please specify your preferred file format by entering the number corresponding to the format name below"
echo "1:avi 2:mp3 3:aac 4:best(program will pick the the best audio format available (aac, mp3, m4a, wav, vorbis))"
read format
if [ "$format" = "1" ]; then
orders="-qt"
elif [ "$format" = "2" ]; then
orders="-qt --extract-audio --audio-format mp3"
elif [ "$format" = "3" ]; then
orders="-qt --extract-audio --audio-format aac"
elif [ "$format" = "4" ]; then
orders="-qt --extract-audio --audio-format best"
else
echo "You did not enter a valid option (1,2,3 or 4) :("
exit
fi
echo "$orders" (debug stuff)
-------------------------------------------------------------------------------------------
Here is what happens when I run the script:
austin@Ruby:~$ ./meddownload.sh http://www.youtube.com/watch?v=g34B-YOaC7c&ob=av2e
[1] 1001
austin@Ruby:~$ Please specify your preferred file format by entering the number corresponding to the format name below
1:avi 2:mp3 3:aac 4:best(program will pick the the best audio format available (aac, mp3, m4a, wav, vorbis))
1
-bash: 1: command not found
[1]+ Stopped ./meddownload.sh http://www.youtube.com/watch?v=g34B-YOaC7c
And here is what happens when I enter a non-URL as the argument (this shows that the URL is mostly likely the cause of the problem):
austin@Ruby:~$ ./meddownload.sh iuniuniun
Please specify your preferred file format by entering the number corresponding to the format name below
1:avi 2:mp3 3:aac 4:best(program will pick the the best audio format available (aac, mp3, m4a, wav, vorbis))
1
-qt
the url
http://www.youtube.com/watch?v=g34B-YOaC7c&ob=av2emust be quoted as it contains a&use: