Pipe output from one command to another command's non standard input
You can't use a pipe if the second command you are running doesn't read from its standard input. However, you can do something like
cd $(which someapplication)
or, since you need a directory name for cd
and not an executable name:
cd $(dirname $(which someapplication))
The $(...)
shell operator executes the command within parentheses and substitutes its output into the command line.
Related videos on Youtube
Avlaxis
Updated on September 18, 2022Comments
-
Avlaxis almost 2 years
I would like to do something similar to the following:
which someapplciation | cd outputfrompreviouscommand
The command
which
provides a directory and I would like to be able to make that output my current working directory without using a programming language i.e.awk
,bash
,perl
, etc. and to only use the pipe command.To further give an example:
which vi
provides the output
/some/dir
I would like my working directory to be moved to that directory which I can test by using the
pwd
command which should have the output that matches of/some/dir
.-
Jakob Bennemann about 10 yearsActually,
which executable
provides the output/path/to/executable
, not its directory. So,cd
ing to the output ofwhich
won't work.
-