1827243 Members
2262 Online
109716 Solutions
New Discussion

backticks doesn't work

 
SOLVED
Go to solution
Reinhard Bayer
Occasional Contributor

backticks doesn't work

Hi there

It looks like a little problem with backquotes (backticks)
If I insert the following command
echo `uname -n`
the result is
uname -n
instead of the real hostname. So i suggest that there is a problem with the command substitution in correlation with backquotes.

Any hint to resolve this prob

Thanks in advance
Reinhard



11 REPLIES 11

Re: backticks doesn't work

What shell are you using?

Duncan

I am an HPE Employee
Accept or Kudo
Alex Glennie
Honored Contributor

Re: backticks doesn't work

try echo 'uname -n' ie back tick sloping left to right works for me with posix shell
Alex Glennie
Honored Contributor

Re: backticks doesn't work

just noticed looking at this post in different browsers show's different styles of back tick ..... in netscape 6.* my answer looks the same as yours !
Greg Martin
Advisor

Re: backticks doesn't work

Reinhard,

echo `uname -n` works for me. I get my hostname.

Funky keyboard? cat some backticks to a file, do an od, and compare to an ascii table. Are you really typing backticks? Foreticks 'uname -n' or quotes would act as you describe.

Otherwise, something funky in your shell config changing the meaning of delimiters?

greg.
Hartmut Lang
Trusted Contributor

Re: backticks doesn't work

Backticks are a pain to me, because they are so hard to distinguish from all the other quotes.
So i prefer:
echo $(uname -n)

Works with posix-shell and maybe in ksh too.

Hartmut
Bill McNAMARA_1
Honored Contributor

Re: backticks doesn't work

I agree with Harmut,
the HOSTNAME=$(hostname)
method is much cleaner (and does work with ksh)

Bill
It works for me (tm)
Reinhard Bayer
Occasional Contributor

Re: backticks doesn't work

sorry there's a typo. The result isn't
uname -n
it's
`uname -n`

Duncan: It's the same behavior in POSIX and Korn Shell.

Alex: The back ticks are the right one, from top left to right bottom

Steven Sim Kok Leong
Honored Contributor

Re: backticks doesn't work

Hi,

What shell are you using?

# echo $SHELL

Try this:

# sh
# echo `uname -a`

what is the output you get?

Hope this helps. Regards.

Steven Sim Kok Leong
Reinhard Bayer
Occasional Contributor

Re: backticks doesn't work

Hi Steven

The output is still the same: `uname -n`

Steven Sim Kok Leong
Honored Contributor

Re: backticks doesn't work

Hi,

Could your server have been rootkit'ed? ;-)

In any case, check the environment:

# sh
# env
# set

Hope this helps. Regards.

Steven Sim Kok Leong
Bill Hassell
Honored Contributor
Solution

Re: backticks doesn't work

The backtick (also known as the grave accent) is deprecated--a fancy name for obsolete. Check the man pages for sh-posix and ksh under Command Substitution. The backticks are a real pain because they are so easy to misinterpret, especially with the wide variety of fonts and displays. Consider what happens on a browser when the desired font is not available: another one is substituted, and some (really bad) fonts display apostrophes as well as grave accents exactly the same way.

As mentioned the preferred way (even bash says 'the old way') is to replace all command substitutions with the $(...) construct. This also makes nesting of commands very simple (no escaping necessary). Now your specific problem may be due to keyboard mapping. All that the shell cares about is the character bitpattern you typed. To decode what the shell sees, do this:

xd
`'
(then type CTRL-D)
0000000 6027 0a00
0000003

What this incantation does is to run the hex decoder program (xd), then you press various keys, followed by CTRL-D which terminates input. xd then displays 6027 which is the hex values for the two characters. 60 is the grave accent (backtick, backqoute, reverse apostrophe, etc) and 27 is the single quote or apostrophe. 0a is the CR or Retrun key and 00 is the marker for the end of an ASCII file.

HINT: man ASCII


Bill Hassell, sysadmin