Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I make a bash script work correctly when I input an URL as an argument
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <pre><code>#!/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) ------------------------------------------------------------------------------------------- </code></pre> <p>Here is what happens when I run the script:</p> <pre><code>austin@Ruby:~$ ./meddownload.sh http://www.youtube.com/watch?v=g34B-YOaC7c&amp;ob=av2e </code></pre> <p>[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</p> <pre><code>[1]+ Stopped ./meddownload.sh http://www.youtube.com/watch?v=g34B-YOaC7c </code></pre> <p>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):</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload