0

I am trying to pass result of which env to nano by this command nano < which env, but it seems, that I didn't understand the whole concept.

When I execute this I assume that: which env STDOUT will go to the nano STDIN. So this will equal to nano /some/path. But, apparently, I am wrong.

Also I tried which env | nano with same purpose, but output was:

Received SIGHUP or SIGTERM

Can somebody clarify this?

5
  • 1
    which env | nano -, where - means stdin.
    – MetNP
    Nov 29, 2016 at 17:35
  • @MetNP same result Nov 29, 2016 at 17:37
  • then your nano version is older (must be >=2.2 for stdin feature, you can check with nano -V ). then workarround would be: nano <(which env)
    – MetNP
    Nov 29, 2016 at 17:41
  • I'm assuming that env in your system is something editable by nano (it's a 64-bit Mach executable on mine, so I don't really want to risk corrupting it), so I substituted the cd command and nano $(which cd) does what you are expecting, at least on OSX.
    – Thomas N
    Nov 29, 2016 at 17:44
  • @ThomasN @MetNP Yes, also I can nano which env``, but also I hoped for a little bit more detailed answer with explanation how it works and why my solution does not. Nov 29, 2016 at 17:48

1 Answer 1

1

nano, like most text editors, expects a file name to edit as its command-line argument, not as standard input.

$ which env | nano    # pass as standard input, does not work
$ nano "$(which env)" # pass as command-line argument, works

So it's not working because that's not how nano expects to be used.

With some editors (apparently not your version of nano), you can use:

$ which env | some-other-editor -  # note hyphen as file name

to edit standard input as text (you'd be editing a document with the string "/usr/bin/env", not the program /usr/bin/env itself).

Also, if you want to change delimited names on standard input into arguments, xargs will do that for you.

PS: which doesn't always do what you want, consider command -v instead. For details, see Why not use "which"? What to use then?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .