Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: bash alias suggest-ation

by archen (Pilgrim)
on Jan 05, 2002 at 02:51 UTC ( #136398=note: print w/replies, xml ) Need Help??

in reply to bash alias suggest-ation

okay, newbie level question :)

why are you printing on STDERR?

Replies are listed 'Best First'.
Re: Re: bash alias suggest-ation
by khkramer (Scribe) on Jan 05, 2002 at 03:42 UTC

    Not a newbie-level question at all...

    The tricky thing about this script is getting it to interact properly with the system environment. There are a couple of problems: 1) you can't get at the history list from inside the script because "history" is a shell built-in and the ".bash_history" file isn't kept up to date, and 2) you can't create aliases from inside the script because there's no way to export aliases out to the calling context.

    The first problem is addressed by taking the history list as input. (But not simply as STDIN, because then you couldn't prompt the user for input.)

    The second problem is solved by using the script in a "command substitution" context -- surrounded by backticks or $(). The only thing that gets printed on STDOUT is the name of the file to which the script writes the "alias foo='bar'" commands. That filename is what the bash "source" builtin sees. So, you don't have access to STDOUT for the interface (it doesn't even show up on the terminal): you have to use STDERR instead. Definitely a kludgy hack, but it works fine for this purpose.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://136398]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2021-04-23 14:26 GMT
Find Nodes?
    Voting Booth?

    No recent polls found