How can I create a ksh alias with multiple commands that take parameters ?

How can I create a ksh alias with multiple commands that take parameters ?

Post by Scott » Sat, 10 Jun 2000 04:00:00



I have been puzzling over this for a couple of hours.  I am trying to create
an alias in the korn shell under Solaris 2.6 that will create a directory
then cd to it.  I know I did this once upon a time but now cannot figure it

starting out:

alias mcd='mkdir $1;cd $1'

It gives me a mkdir usage error.  I think it is the usage of the semicolon
command separator because

alias mcd='mkdir $1'

works fine.  Anyone know what I am doing wrong ?

Thanks, Scott

 
 
 

How can I create a ksh alias with multiple commands that take parameters ?

Post by Scott » Sat, 10 Jun 2000 04:00:00


Okay, I did that (defined the function in .kshrc, which is pointed to by my
ENV variable), then envoked a new session, could see the function defined,
but when I ran it, it created the directory allright, but gave the error:

/bin/ksh: mydirectory: not found

The directory IS there.  Seems like a context problem somehow.  Before I ran
it I wondered if I somehow needed to source it, so the shell would inherit
the same environment after execution (so I would wind up in the new
directory), but sourcing won't work on a function.  What am I missing ?

Thanks, Scott



># I have been puzzling over this for a couple of hours.  I am trying to
create
># an alias in the korn shell under Solaris 2.6 that will create a directory
># then cd to it.  I know I did this once upon a time but now cannot figure
it

am
># starting out:
>#
># alias mcd='mkdir $1;cd $1'
>#
># It gives me a mkdir usage error.  I think it is the usage of the
semicolon
># command separator because
>#
># alias mcd='mkdir $1'
>#
># works fine.  Anyone know what I am doing wrong ?

>man ksh

>use functions

>function mcd
>{
>    mkdir $1 && cd $1
>}


 
 
 

How can I create a ksh alias with multiple commands that take parameters ?

Post by Chris F.A. Johns » Sun, 11 Jun 2000 04:00:00


: I have been puzzling over this for a couple of hours.  I am trying to create
: an alias in the korn shell under Solaris 2.6 that will create a directory
: then cd to it.  I know I did this once upon a time but now cannot figure it

: starting out:

: alias mcd='mkdir $1;cd $1'

Try this:
        alias mcd='echo $1;mkdir $1;cd $1'

You'll see that you are executing:

        echo;mkdir;cd $1

What you need is a shell function:

mcd() {
        mkdir $1
        cd $1

Quote:}

--
        Chris F.A. Johnson

        -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
               Everything in moderation - including moderation  
 
 
 

1. Parameters for alias csh to ksh

--
I'm converting from csh to ksh and have some aliases which
accept parameters in csh which I'm having a hard time
duplicating in ksh.  For example:

In my .cshrc file I have the alias

   alias ll 'ls -alF ''\!*'' | more'

This would page an entire directory list if I typed in

   ll

and also accept patterns,

   ll a*

paging all the files beginning with an 'a'.  In my .kshrc
file I've tried many variations of

   alias ll='ls -alF "$*" | more'

When I type in 'll' this produces what I would expect, a paged
entire listing of the directory.  When I type in 'll a*', most
of the variations that produce anything give me a more'd listing
of the entire directory plus the contents of files starting with
'a'.  What is going on here and how do I get it to work like my
c-shell?

Thanks for any information you can give me.

M. Chris Golledge


2. hosts.equiv and .rhosts

3. parameter passing in ksh alias

4. TCP connections TIME_WAIT state problem!!

5. ksh and passing parameters to an alias

6. scribe converter?

7. Passing parameters to an alias in ksh ...under AIX

8. tcp/ip configuration

9. ksh alias and parameters question

10. Parameter in ksh alias

11. Q: Problem using ksh set command to set positional parameter

12. How can I overwrite a command-line parameter in ksh?

13. How do setup a command alias with parameters?