Find the answer to your Linux question:
Results 1 to 8 of 8
The following is a part of a script I've found on the Internet. My question is: When do you use the quotation marks around the URL? The manual page of ...
  1. #1
    Just Joined!
    Join Date
    Dec 2004
    Posts
    2

    wget

    The following is a part of a script I've found on the Internet. My question is: When do you use the quotation marks around the URL? The manual page of wget does not say anything about using the marks.


    wget -O $dns_tmp --http-user=$ZEuser \
    --http-passwd=$ZEpasswd --no-check-certificate \
    "https://dynamic.website.com/auth/dynamic.html?host=$domain"

  2. #2
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    I would guess because the $domain is to be evaluated, it is a variable and not to be taken literally as a string for wget. With that said it should be evaluated anyway...so perhaps it's to contain certain escape characters that may interrupt the shell?

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    wget never sees the quotation marks. It's the shell that sees them and reacts to them. But it has nothing to do with "interrupting" the shell. The reason for the quotation marks is the question mark. Run this script to see why the author of the original script is showing good shell scripting habits.
    Code:
    #!/bin/sh
    
    touch xxxaxxx
    touch xxxbxxx
    touch xxxcxxx
    
    echo xxx?xxx
    echo "xxx?xxx"

  4. #4
    Linux Guru
    Join Date
    Nov 2004
    Posts
    6,110
    Ah yeah, I forgot that ? is a wildcard for any single character. Thanks for the clarification wje_lf

  5. #5
    Just Joined!
    Join Date
    Dec 2004
    Posts
    2
    Thank all of you for quick replies.

    Although I understand the reason why you want to use " " around a string, but the question I posed concerns itself with wget and its arugument.

    wiget -options URL.
    The question still remains: Does the URL need to be surrounded by " marks? In other words, when the URL is surrounded by the quotation marks, would it be recognized as an URL?

    By the way, I got the same result with and without the quotations marks.
    Last edited by pinesol; 11-07-2007 at 05:04 PM. Reason: To clarify a point.

  6. #6
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    URL is parameter that you are passing to wget. It doesn't matter if you use double or single quotes or none unless you are passing variable using $ sign. Wildcards don't make any difference in static parameters.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  7. #7
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Quoth the highly esteemed devils_casper:
    It doesn't matter if you use double or single quotes or none unless you are passing variable using $ sign.
    I beg to differ. Consider the following shell script:
    Code:
    #!/bin/bash
    
    wget -O a1.html http://www.google.com/search?hl=en&q=fred&btnG=Google+Search
    That should retrieve the results from searching for fred in google.

    When you run it, you observe two things.

    The second thing you observe is that the output in a1.html seems to give you not any search results, but the main google page.

    The first thing you observe is that you don't seem to get a prompt back from the shell after completion. Actually, the returned prompt is there, usually on the line right after the one where you keyed in the script name. In other words, bash gave you the prompt back immediately, without waiting for the command to finish.

    What happened?

    Take a look at this line again:
    Code:
    wget -O a1.html http://www.google.com/search?hl=en&q=fred&btnG=Google+Search
    Ooo. Doubleplusungood. See that question mark in there? To see what's going on, run this shell script:
    Code:
    #!/bin/bash
    
    echo -O a1.html http://www.google.com/search?hl=en&q=fred&btnG=Google+Search
    The shell will act as though you had entered
    Code:
    echo -O a1.html http://www.google.com/search?hl=en &
    An unescaped, unprotected ampersand in a bash shell command will cause the command to be executed in the background, and you will get a prompt back immediately. I didn't know this before now, but apparently what comes after the ampersand is simply thrown away.

    So it's a good habit to put at least double quotes around any URL on a bash command line (or, as devils_casper reminds us, single quotes if you don't need or want any $ in the URL to be bash-interpreted).

  8. #8
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Thanx a lot for explanation wje_lf. I appreciate it. Thanx again.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...