Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I don't undertsand why, in Bash:

  • echo $(hostname --fqdn) works,
  • echo $(id -un) doesn't (id: –un: No such user).

Backticks give the same results.

Is there some good practice for using this notation? Does the id command have something special regarding its use in such a way?

Hereunder, some details as it seems it works on other systems:

  • lsb_release -a: SUSE Linux Enterprise Server 11 (x86_64),
  • which id: /usr/bin/id,
  • id -un works alone.
share|improve this question
try to replace $(id -un) with $(/usr/bin/id -un) – Olivier Dulac Mar 13 '14 at 9:34
...You wrote a shell script using Word. I humbly suggest you invest in pretty much any actual editor. – Jenny D Mar 13 '14 at 13:42
up vote 5 down vote accepted

I noticed a subtle difference between the command posted:

echo $(id -un)

and the error message for it:

id: –un: No such user

The two "hyphens" are different, the second one being a tiny bit longer. It looks like the error message was copied and pasted from the original, but the command was re-typed. The original command most likely contains the wrong kind of hyphen. This explains why no one could reproduce the error message.

This kind of error mostly has one of two reasons:

  • Code was copied from websites, where it was typeset using a bad formatter / syntax highlighter.

  • Code was typed in an inappropriate editing environment, like Microsoft Word. Word might change something you type into a typographical better, but unexpected variant, like different hyphens, different quotes, or some other space sign.

Coincidentally, there was just a popularity contest challenge on Codegolf, where one answer used a similar "trick" to yield a difference that was not even visible:

share|improve this answer
Code was typed in an inappropriate editing environment, like Microsoft Word. Actually, most Windows-based text editors have this problem too (using the wrong hypen, at least). I've even run into it doing copy-pasta from PowerShell, so it seems to be much more of a Windows-platform thing than any editor in particular. – HopelessN00b Mar 13 '14 at 13:34
In fact, I have simplified the problem with a advice of one of my coworkers: $(whoami) instead of $(id -un). And also disabled this auto-correction in Word! – PomCompot Mar 13 '14 at 16:20
@PomCompot Stop using Microsoft Word for shell scripts!!! – ewwhite Mar 13 '14 at 18:39
At least for programming. :) – Dubu Mar 13 '14 at 18:39
You fixed the wrong problem! – MikeyB Mar 13 '14 at 18:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.