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

Re: Using aliases or functions in bash script



On Sat, 26 Jan 2008 18:03:32 +0000
Tzafrir Cohen <tzafrir@cohens.org.il> wrote:

> On Sat, Jan 26, 2008 at 12:44:42PM -0500, Daniel Dickinson wrote:
> > On Sat, 26 Jan 2008 17:12:56 +0000
> > Tzafrir Cohen <tzafrir@cohens.org.il> wrote:
> > 
> > > On Thu, Jan 24, 2008 at 03:55:51AM +0000, T o n g wrote:
> > > 
> > > > I'm wondering if you have read my OP or not. Read it again pls.
> > > 
> > > Yes I have. Use functions. Don't use aliases.
> > > 
> > 
> > On command-line:
> > 
> > function dt () {
> > 	push +$1
> 
> And this should do? Is this supposed to be "pushd"? Why the '+'?
> pushd +1?

Erm, rather pushd +$1
I just copied the example function the original poster gave, since it
is his question.
> 
> > }
> > 
> > In test.sh
> > 
> > #!/bin/bash
> > 
> > pwd
> > $(dt $(pwd))
> > cd /tmp
> > popd
> > pwd
> > 
> > ./test.sh
> > Line 2 errors out.  
> 
> And those error are?
> 
./test.sh: line 4: dt: command not found
./test.sh: line 6: popd: directory stack empty

However, the point isn't the particular script, that was just an quick
example I cooked up to demonstrate the original poster's problem.  A
function defined in the current shell is not available to a script
executed from that shell (perhaps it would with sh test.sh, I didn't
test that).

IOW I decided to see what his problem was rather than just shooting in
the dark.

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: