Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Re: bash alias suggest-ation by khkramer
in thread bash alias suggest-ation by khkramer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-03-29 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found