Hack 36. Display output of any command in the prompt

by Ramesh

You can display output of any Linux command in the prompt. The following example displays three items separated by | (pipe) in the command prompt:

  • !: The history number of the command
  • \h: hostname
  • $kernel_version: The output of the uname -r command from $kernel_version variable
  • \$?: Status of the last command
  1. ramesh@dev-db ~> kernel_version=$(uname -r)
  2.  
  3. ramesh@dev-db ~> export PS1="\!|\h|$kernel_version|\$?> "
  4.  
  5. 473|dev-db|2.6.25-14.fc9.i686|0>