2

I have a kind of "bash newbie" question: how do I pass the result output of one command to exec. The result of the first command is the name of other command, so exec should be able to execute it.

lwt
  • 23
  • 2
  • 1
    Are you sure you want `exec`? If you just want to execute the result of a command, you don't need `exec`, just run it directly. What `exec` does is *exit the current shell* and replace it with the specified program. – Gordon Davisson May 17 '13 at 19:31

1 Answers1

1

Use command substitution. A contrived (and rather useless) example:

exec $(echo whoami)

The $(…) will be replaced with the output of the command within. There's also the variant with backticks (`), but it's not recommended for various reasons.

slhck
  • 223,558
  • 70
  • 607
  • 592