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
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||