On Thu, May 14, 2009 at 05:55:35PM +0300, Dotan Cohen wrote:
> I am using a Debian-based distro (Ubuntu). Often I need to use the
> output of one terminal command as the input for another. A classic
> example is the  which command:
> $ which firefox
> /usr/bin/firefox
> $
> 
> Now, I would like to use that output as input, to start firefox. Other
> than manually typing it in, is there a way for the user to use the
> output directly?
> 
> Another example is when the OS lets the user know that she needs to
> install a program and gives her the command to install it:
> $ ekiga
> The program 'ekiga' is currently not installed.  You can install it by typing:
> sudo apt-get install ekiga
> bash: ekiga: command not found
> $
> 
> In contrast to the "which" example, the text that the user needs is
> buried in the output. Is there a way to use it anyway, without
> retyping (and without using the mouse, which I often do not have).
> Thanks!

I'm not sure, but you may be seeing the 'command-not-found' hook that was
added to bash 3.x as a patch in debian and ubuntu, and I think programmed
in ubuntu to install the program (or maybe just to suggest doing that,
as in your example).  This scheme was accepted into bash 4.0 with some
improvements, e.g., giving access to the failed command's argument list,
vs the older patch which only kept the command itself.

(If you're interested, you could check for a function called
command_not_found_handler() or similar in your shell environment, and
just see what it contains.  That function could be redefined for other
purposes, but, again, it only provides access to the command, not to
the arguments (unless that's been fixed since I've looked.)

I'm not sure how that relates to the subject question.  These things
differ according to what shell you're using, but in bash `backticks` are
the "old" way of treating shell output as input, and the $(...) construct
is the "new" way.

You might try something like this, which works for me on bash in lenny:

    $ exec $(which iceweasel)

If you don't use exec the process will run as a child process of the
shell, while exec replaces the shell with the new process.

Ken

-- 
Ken Irving


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to