1

Suppose I have a program called mktemp which creates a random tmp directory in /tmp and also produces a string output of the directory address

Input[0]: mktemp
Output[0]: /tmp/tmp.MkrKAscwwk

How can I redirect the output of mktemp so that I can change my directory to that I just created? Meaning I Don't have to do cd /tmp/tmp.MkrKAscwwk.

  • 2
    Or better ... [How can I assign the output of a command to a shell variable?](https://unix.stackexchange.com/questions/16024/how-can-i-assign-the-output-of-a-command-to-a-shell-variable) – pLumo Apr 24 '19 at 08:07
  • 1
    `cd "$(mktemp | tail -n1 | cut -d: -f2)"` – Arkadiusz Drabczyk Apr 24 '19 at 08:11

0 Answers0