How to print and use a command output in a one-liner?
How about tee
with /dev/tty
?
$ gcc -o $(mktemp | tee /dev/tty) hello.c
/tmp/tmp.UBSSnulNn2
$ /tmp/tmp.UBSSnulNn2
Hello, world!
Related:
- using tee to output intermediate results to stdout instead of files
Switching things around in gcc -o $(out=$(mktemp); echo $out)
:
out=$(mktemp); echo "$out"; gcc -o "$out" hello.c
... which also conveniently leaves the path in the variable for later uses. (Presumably you don't want to just see the path in the output to admire the beauty of mktemp
's random name generation, right? You want that path to use it elsewhere.)