LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-30-2013, 08:01 PM   #1
Fnux
LQ Newbie
 
Registered: Mar 2013
Posts: 18

Rep: Reputation: Disabled
Unhappy Lost with single and double quotes with bash!


Hello all,

I'm trying to automatize the installation of weighttp, a simple and light web server benchmark tool that is using libev.

I'm using Ubuntu Server 12.04.4 LTS without a GUI.

I wrote a little script (install-weighttp.sh) to do so, but the last part doesn't work.

Code:
#!/bin/bash
# Download and Install both libev and weighttp.
cd Downloads
wget http://dist.schmorp.de/libev/libev-4.15.tar.gz
tar -xzf libev-4.15.tar.gz
apt-get -y build-dep libev
apt-get -y install libev-dev
cd libev-4.15
./configure
make
sudo make install
cd ..
wget http://cgit.lighttpd.net/weighttp.git/snapshot/weighttp-master.tar.gz
tar -xzf weighttp-master.tar.gz
cd weighttp-master
gcc -g2 -O2 -DVERSION='"123"' src/*.c -o weighttp -lev -lpthread <- This is where I've a problem !
sudo cp ./weighttp /usr/local/bin
cd ../..
As a matter of fact, the compilation of weighttp doesn't work since its command line obvioulsy stops when the first single or double quote is intrepreted.

However, I've read a number of documents with regard to bash and its quotes, but no one gave me a way to make what I expect to do.

I've try a number of combinations using the character \ before the single and/or the double quotes but I didn't find any one working !

Note: If I use all these commands, one after one in a terminal session, it works !

However, I'ld love to make the install-weighttp.sh script working too.

Any help will be trully appreciated because I'm a real dumb newbee with bash.

Cheers.
Fnux
 
Old 03-31-2013, 11:07 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
One secret is to stop thinking of quotes as enclosures, and more like toggle switches. They turn shell interpretation of characters on and off.* The only difference between single and double quotes is that double quotes continue to allow interpretation of a few characters, specifically "$,`,\", which allows parameter expansion and backslash escaping to continue happen. See the QUOTING section of the bash manpage for more details on how various characters are treated.

Another thing to understand is that pretty much everything the shell does, including quoting, only has one final purpose -- to create a list of arguments (tokens) for the command being run. Syntactical quotes are actually among the first things processed, and are removed from the line. Only if a quote mark is escaped by another quote or backslash will it become part of the argument itself. But the vast majority of commands do not accept literal quotes anyway.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/BashParser

As for this:

Code:
gcc -g2 -O2 -DVERSION='"123"' ...
The first single quote toggles interpretation off, so everything up to the next single quote, including the two double-quotes, are treated as literal characters. The single quotes themselves are removed from the line. So after processing by the shell, gcc gets launched with the literal string:

Code:
-DVERSION="123"
...including the quotes. Now, does gcc need it to look like this, or not? I really don't know, as my experience with it is limited. But I imagine that it doesn't, so in this case you probably don't need any quote marks at all.


-----
*Note that there are certain situations where nested containers create separate interpretation contexts. i.e.:

Code:
echo "A nested command: $( cat "filename with spaces.txt" )."
echo "A parameter substitution (left hand side): ${var/'string$with`special|characters*'/replacement string}"
The internal sets of quotes are treated separately from the outer ones, but they still act as toggles inside their respective parsing environments.
 
1 members found this post helpful.
Old 03-31-2013, 11:38 PM   #3
Fnux
LQ Newbie
 
Registered: Mar 2013
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thank you for all these precisions that solved my problem.

All the best.
 
  


Reply

Tags
bash scripting, ubuntu 12.04



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
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 03:03 PM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
gvim - double quote char always replaced with two single quotes in special modes JazzItSelf Linux - Software 4 09-16-2008 11:26 AM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
In BASH shell, what is the difference in usage between single and double quotes? davidas Linux - Newbie 2 04-05-2004 03:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:30 AM.

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
Open Source Consulting | Domain Registration