[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Mar 2004 ]

Re: [edlug] Trouble With Scripts



Keith W Wyse <keithwwyse@xxx.xxx.xxx> writes:

> I wonder if anyone can answer this question;
> I've been trying to create a script which will alias a word with a
> command with the simple line
>
> #!/bin/bash -v
> alias someword='/somepath/somecommand &'
>
> Unfortunately when I list the aliases in the gnome-terminal window after
> having run the script, the alias does not exist.

You need to inset the alias in to the current shell, while the script is
running in a new (sub)shell.  Ways around this:

1) Source the script in to the current shell using ". script".  The only
way (AFAIK) you can pass in parameters is as shell variables,
unfortunately.

2) Add the aliases to your .bashrc, so they get added to every shell you
run.

3) Make your script fire up a new shell and add the aliases to it.  This
is a bit messy -- it means that you're working in a shell inside your
shell, to however many levels you run the script, and to log out you'll
need to exit out through all the shells.

If you can, I recommend option (2).  You can have a look at KeyChain as
an example of how this problem can be annoying...  Unfortunately it's a
pretty basic thing (and it can be very useful sometimes).

OK,
-- 
Andrew Aylett | www.aylett.co.uk | 1.79 x 10^12 furlongs per fortnight...
andrew@xxx.xxx.xxx | answer==42 |  -- it's not just a good idea, it's the law!

Attachment: pgp00005.pgp
Description: PGP signature



This archive is kept by wibble@morpheux.org.DONTSPAMME
homepage