What does the "`" Characteter Do?

2007-10-08 Thread duff

What does this "`" character do in the command line? 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.

Any help you can give would be appreciated.

duff

-- 
View this message in context: 
http://www.nabble.com/What-does-the-%22%60%22-Characteter-Do--tf4589275.html#a13099929
Sent from the Gnu - Bash mailing list archive at Nabble.com.





Re: What does the "`" Characteter Do?

2007-10-08 Thread Bob Proulx
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




Re: What does the "`" Characteter Do?

2007-10-08 Thread Mike Stroyan
On Mon, Oct 08, 2007 at 01:59:25PM -0600, Bob Proulx wrote:
> 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.

  The ` character does format correctly on debian for some locales.
I get good output with 
  LANG=C man bash

  The problem comes from formatting of ` to an abstract 'left quote'
value.  That can be avoided by quoting it in the manual source as \`.
That is an understandable error.  Even "man groff" gets that wrong.

-- 
Mike Stroyan <[EMAIL PROTECTED]>