putting something into single quotes in a bash script

Patrick O'Callaghan pocallaghan at gmail.com
Wed Feb 2 21:32:23 UTC 2011


On Wed, 2011-02-02 at 13:43 -0700, Petrus de Calguarium wrote:
> What is the difference in a bash script when one places something between 
> single quotes:
> 
> - using the apostrophe, '
> - using the accent grave, `
> 
> ?
> 
> Eg.,
> 
> ps -fu 'whoami'
> ps -fu `whoami`
> 
> They produce entirely different results.

Of course they do. They are entirely different things. The first one is
for quoting strings which might contain Shell metacharacters. The second
is to execute a command and insert its output as the value of the
string, e.g.

ls -l `find ~/.kde`

This is equivalent to:

ls -l $(find ~/.kde)

but the latter is a more recent form (it has the advantage of being
nestable, which the older form isn't).

And then there's the difference between " and ' ...

I recommend reading up on bash to fully understand this last part. It's
not trivial to explain.

poc



More information about the users mailing list