Making nano accepting previous piped output as a file path

2

When I run the following command in linux:

find / -iname httpd.conf

I get:

/usr/local/apache/conf/httpd.conf

I want to use nano to edit this file, lazy to type the file path again, I used:

find / -iname httpd.conf | nano

It didn't work, nano quickly opened and exited, then I found a nano.save file in the directory that I ran this command. Using cat command on nano.save, it outputs the text: /usr/local/apache/conf/httpd.conf

This means nano thinks the previous piped output as a string that I want to write to a file, but the fact is, I would like nano to think it as the file path so that it actually opens the file for me to do the editing.

How can we make nano accept previous piped output as a file path?

bobo

Posted 2010-02-06T13:25:24.553

Reputation: 1 649

Answers

5

Nano behaves like expected, since a pipe is used to connect on program's output to another one's input.

What you want instead is to use the output of find as an argument for nano:

nano `find / -iname httpd.conf`

Benjamin Bannier

Posted 2010-02-06T13:25:24.553

Reputation: 13 999

But why does nano consider the input as the file content rather than the file path? – bobo – 2010-02-07T01:18:42.137

Because pipes connect output to inputs http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html. You want to substitute a nano parameter with a program output http://tldp.org/LDP/abs/html/commandsub.html.

– Benjamin Bannier – 2010-02-07T05:20:26.253