Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

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

From: Daniel Dickinson <cshore(at)wightman.ca>
Date: Sat Jan 26 2008 - 17:19:04 EST


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

Do you need help?X

#!/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,

Do you need more help?X

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

-- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Received on Sat Jan 26 17:20:41 2008

This archive was generated by hypermail 2.1.8 : Thu Mar 06 2008 - 14:14:52 EST


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library