-1

I'm trying to store the output the which command. Here's what I've tried:

OUT=$(which gsutil)
echo "$(OUT)"

But it doesn't work and prints an empty line.

mokiliii Lo
  • 587
  • 3
  • 13
  • 26

1 Answers1

4

The which command is a broken heritage from the C-Shell and is better left alone in Bourne-like shells.

Instead use command -v:

OUT=$(command -v gsutil)
echo "${OUT}"
SikorskyS60
  • 160
  • 14
  • But of course, storing the standard output only so you can immediately `echo` it to standard output is a [useless use of `echo`](https://www.iki.fi/era/unix/award.html#echo) – tripleee Mar 18 '22 at 08:58
  • It is. I sure hope that the variable will be used differently by the questioneer. – SikorskyS60 Mar 19 '22 at 09:24