[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Using aliases or functions in bash script



On Sat, 26 Jan 2008 21:40:12 +0000 (UTC)
T o n g <mlist4suntong@yahoo.com> wrote:

> On Sat, 26 Jan 2008 13:32:57 -0800, Andrew Sackville-West wrote:
> 
> >> >> I'm wondering if you have read my OP or not. Read it again pls.
> >> > 
> >> >     source ~/.bashrc
> >> 
> >> Guess that I am having bad lucks now, having two people replied
> >> without even reading my question, and the two replies are the only
> >> replies that I get... 
> > 
> > how does this not answer your question? Ken suggests that you need
> > to source .bashrc. That makes sense to me. . .
> 
> <Sigh....> Read it again pls, my OP, the last line.
> 
> 3rd now. 

Ok, here's a question (as I missed the very first message): what are you
trying to accomplish? If you just want to use functions that are
in .bashrc in some other script then you can define the function
in .bashrc and then

source ~/.bashrc

so, .bashrc has:

...
function dt () {
	pushd +$1
}
...

and other-script.sh has

#!/bin/bash

source ~/.bashrc

pwd
$(dt $(pwd))
cd /tmp
popd
pwd

That will execute function dt (which is a pushd) with the current
working directory, the function dt being the one which was defined
in .bashrc

Now, for the alias you could define a function that does whatever it is
want the alias to do, then create an alias that executes the function.

Then in other-script.sh you either recreate the alias (if for some
reason you really have to have an alias), or you can execute the
function as with dt.

If there is more to it than that you need to try doing your OP over
again, only stating your problem more clearly.

Regards,

Daniel


-- 
And that's my crabbing done for the day.  Got it out of the way early, 
now I have the rest of the afternoon to sniff fragrant tea-roses or 
strangle cute bunnies or something.   -- Michael Devore
GnuPG Key Fingerprint 86 F5 81 A5 D4 2E 1F 1C      http://gnupg.org
No more sea shells:  Daniel's Weblog    http://cshore.wordpress.com

Attachment: signature.asc
Description: PGP signature


Reply to: