bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What does the "`" Characteter Do?


From: Bob Proulx
Subject: Re: What does the "`" Characteter Do?
Date: Mon, 8 Oct 2007 13:59:25 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

duff wrote:
> What does this "`" character do in the command line?

Command Substitution.  And I was a little surprised to see that when I
looked for that character in the man page that it did not appear
anywhere within it in the Debian formatting of the manual.  It appears
that there is a formatting issue surrounding the output of that
character and this may have prevented you from finding that character
by a search of the documentation.  It is also listed as the backquote
character there.  Sometimes people call these "backticks" too.

In the manual, with a manual fix to the formatting of the `...`:

   Command Substitution
       Command substitution allows the output of a command to replace
       the command name.  There are two forms:

              $(command)
       or
              `command`

       Bash performs the expansion by executing command and replacing
       the command substitution with the standard output of the
       command, with any trailing newlines deleted.  Embedded newlines
       are not deleted, but they may be removed during word splitting.
       The command substitution $(cat file) can be replaced by the
       equivalent but faster $(< file).

       When the old-style backquote form of substitution is used,
       backslash retains its literal meaning except when followed by
       $, `, or \.  The first backquote not preceded by a backslash
       terminates the command substitution.  When using the $(command)
       form, all characters between the parentheses make up the
       command; none are treated specially.

       Command substitutions may be nested.  To nest when using the
       backquoted form, escape the inner backquotes with backslashes.

       If the substitution appears within double quotes, word
       splitting and pathname expansion are not performed on the
       results.

> For example, I am suppose to enter the following command from a
> terminal window when running in a bash shell:
> 
>     # bfu `pwd`/archives/`uname -p`/nightly
> 
> It looks as if the "`" is suppose to evaluate to the output of a command or
> variable. However, that doesn't quite make sense to me in this case.

The `pwd` runs the pwd command which outputs the present working
directory and the output is substituted in place.  The `uname -p` runs
the uname command with the -p option and the output is substituted in
place.  That command line will eventually look something like this, at
least on my machine while sitting in the /var/tmp directory:

  $ echo bfu `pwd`/archives/`uname -p`/nightly
  bfu /var/tmp/archives/unknown/nightly

Note that use of uname -p is not portable and should be avoided in
portable shell scripts.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]