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

Re: [edlug] Trouble With Scripts

On 12 Mar 2004, at 18:38, Keith W Wyse wrote:

Hi all.
I've not been around the list or at meetings recently as I've been
moving house, but that should all be done with by the end of March, so I
should see you all soon.

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.
I've also tried using
function someword() {
/somepath/somecommand &
but this has the same effect - it doesn't exist.
I've been able to create aliases and functions at the prompt, which
appear in the list no problem, and I've had a look at enable both at the
prompt and inside shell scripts, and all is well.
Finally I tried using source to run another script, which works, but is
a bit messy and means having several files lying about.
Can anyone help?
Is there a special way to get an alias to work inside a script?
I'm using bash version 2.05b.0(1) inside Red Hat 8.

Did you try exporting the function within the script?

e.g. export -f someword()

If you don't then any sub-shell of your script will not have access to your function. If you expect
the function to exist after you have run the script then it won't. The only way to get that to work
is to source the script within your current shell.



======================================================================== =====
Graeme Wood Email: Graeme.Wood@xxx.xxx.xxx
Unix Systems Support Phone: +44 131 650 5003
The University of Edinburgh Fax: +44 131 650 6552
======================================================================== =====

You can find the EdLUG mailing list FAQ list at:

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