LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2013, 01:43 PM   #1
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Rep: Reputation: 16
bash: escaping/anchoring args for wget


I use the following wget foo:
Code:
wget -qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain' http://snoop.nsa.gov/snooplist.txt
I want to put the args and stuff in variables and call it up this way:

Code:
wget=/usr/local/bin/wget
wget_args="-qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain'"
url=http://snoop.nsa.gov/snooplist.txt
...but when I call $wget $wget_args $url the header stuff is never passed correctly because it's losing the ticks around 'Content-Type: text/plain'.

I have tried many variations here, enclosing the whole wget_args in ticks, using anchors (escaping) before each tick, and so on. Rather than illustrating all of my failed attempts can someone show me how this might be handled properly?
 
Old 09-28-2013, 02:04 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Try placing the items in an array and calling it:
Code:
wget=/usr/local/bin/wget
wget_args=( -qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain' )
url=http://snoop.nsa.gov/snooplist.txt

$wget ${wget_args[*]} $url
 
Old 09-30-2013, 04:54 PM   #3
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
Grail --that's a smart approach but it still loses the ticks around the header values and as a result they are never passed to the server:

If I run with set -x

+ /usr/local/bin/wget -qO - --no-check-certificate --header=Content-Type: text/plain --header=Accept: text/plain http://snoop.nsa.gov/snooplist.txt
 
Old 10-01-2013, 05:31 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
So it is failing? Not sure if the address is made up, but it does not work for me copying it from your original post anyway.
 
Old 10-01-2013, 12:20 PM   #5
ezekieldas
Member
 
Registered: Mar 2010
Posts: 122

Original Poster
Rep: Reputation: 16
The url I'm using is just a humorous example. What I'm actually using it against is an (internal access only) API that gives either JSON or TEXT responses based on the requested header. Unfortunately I can't find a site that behaves similarly that I could post here as an example.

Yet if you run the following you'll see how the first wget does not include ticks around the header values but the second one does.

I've not yet found a means to maintain those header values...


Code:
set -x 

wget=/usr/local/bin/wget
wget_args=( -qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain' )
url=http://news.google.com/intl/en_us/about_google_news.html

$wget ${wget_args[*]} $url >/dev/null

wget -qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain' http://news.google.com/intl/en_us/about_google_news.html >/dev/null
Code:
+ wget=/usr/local/bin/wget
+ wget_args=(-qO - --no-check-certificate --header='Content-Type: text/plain' --header='Accept: text/plain')
+ url=http://news.google.com/intl/en_us/about_google_news.html
+ /usr/local/bin/wget -qO - --no-check-certificate --header=Content-Type: text/plain --header=Accept: text/plain http://news.google.com/intl/en_us/about_google_news.html
+ wget -qO - --no-check-certificate '--header=Content-Type: text/plain' '--header=Accept: text/plain' http://news.google.com/intl/en_us/about_google_news.html
 
Old 10-01-2013, 01:10 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
Ok ... I was using a different method so missed what you needed initially, but what if you quote within the array:
Code:
wget_args=( -qO - --no-check-certificate "--header='Content-Type: text/plain'" "--header='Accept: text/plain'" )
This keeps the quotes but then the issue will be on how wget interprets what is passed to it??
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using WGET and escaping URL with query string(shared server web hosting CentOS) tinonetic Linux - Server 1 07-14-2010 12:27 AM
Bash escaping super_bash Linux - General 2 08-06-2009 01:04 PM
filename escaping in bash dash9 Linux - Software 1 06-04-2009 11:36 PM
escaping bash shell hectorDUQUE Fedora 5 03-15-2008 07:04 AM
NOT escaping bash history ivanatora Linux - General 3 06-07-2005 02:17 PM


All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration