[comp.unix.questions] KSH questions

stevens@hsi.UUCP (Richard Stevens) (09/28/87)

After 7 years with the C-shell I've just gotten introduced to the
Korn shell, with a new 3b1, and have some questions:

(1)  What documentation is available for the Korn shell ??  I got a man
	page with the 3b1, but that's it.  I also have a copy of a
	paper that appears to be the original one from the Toronto
	Usenix in 1983.  Is there anything newer and better ??
	AT&T has an order code in the 3b1 documentation for a "Shell"
	manual, but I'd bet its just the Bourne shell.  (I'm familiar
	with the Bourne shell and use it for all "shell scripts" - what I'm
	looking for is more details/examples (i.e., more than the man page)
	on the new ksh features like the fc command and functions.)

(2)  Can someone mail me the ksh functions to do the directory pushd/popd ?
	Thanks.

		Richard Stevens
		Health Systems International, New Haven, CT
	           { uunet | ihnp4 } ! hsi ! stevens

kdavis@lamc.UUCP (Ken Davis) (09/29/87)

In article <692@hsi.UUCP> stevens@hsi.UUCP (Richard Stevens) writes:
>After 7 years with the C-shell I've just gotten introduced to the
>Korn shell, with a new 3b1, and have some questions:

As ksh seems to be the "emerging standard", there seems to be
little out on it yet.  Several of the mags have started talking
ksh lately.  If you get some good scripts summarize them and send
them to the net.

-- 
 Ken Davis - Letterman Army Medical Center - San Francisco, CA 
  {ptsfa,well,hoptoad}!lamc!kdavis  kdavis@optimis-pent.arpa 

ndd@duke.UUCP (09/30/87)

In article <692@hsi.UUCP> stevens@hsi.UUCP (Richard Stevens) writes:
>After 7 years with the C-shell I've just gotten introduced to the
>Korn shell, with a new 3b1, and have some questions:
>
...
>
>(2)  Can someone mail me the ksh functions to do the directory pushd/popd ?
>	Thanks.
>
>		Richard Stevens
>		Health Systems International, New Haven, CT
>	           { uunet | ihnp4 } ! hsi ! stevens

I would also be interested in pushd/popd. In addition, I have a problem:
under ksh, I don't belong to any of the groups that I have listed in
/etc/group, just the one in /etc/passwd. Has anyone seen similar
behaviour? Is there a fix?

This is on a Sun 3/280 running SunOs 3.3 and ksh version 6/03/86.

Ned Danieley (ndd@sunbar.mc.duke.edu)
Basic Arrhythmia Laboratory
Duke University Medical Center
Durham, NC  27710
(919) 684-6807 or 684-6942

ekrell@hector.UUCP (10/01/87)

In article <369@lamc.UUCP> kdavis@lamc.UUCP (Ken Davis) writes:

>As ksh seems to be the "emerging standard", there seems to be
>little out on it yet.  Several of the mags have started talking
>ksh lately.  If you get some good scripts summarize them and send
>them to the net.

Dave Korn himself is writing a book on ksh. There's already a preliminary version
and the book should be out before the end of the year.
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill

    {ihnp4,seismo,ucbvax}!ulysses!ekrell

ron@topaz.rutgers.edu (Ron Natalie) (10/02/87)

Here's a couple I wrote for the 5R2 Bourne Shell:
I don't set the prompt to the directory names because I find it
disgusting, but you can do that by doing PS1="$DIRSTACK" in both
popd and pushd.

which() {
   whatis $*
}

pushd()  {
    if cd $1
    then
        DIRSTACK="$1 $DIRSTACK"
        echo $DIRSTACK
    fi
}
popd()  {
    set $DIRSTACK
    shift
    DIRSTACK="$*"
    if test "$1" = "" 
    then
	echo $HOME
    else
        echo $DIRSTACK
    fi
    cd $1
}

abcscnuk@csun.UUCP (Naoto Kimura) (10/10/87)

In article <15249@topaz.rutgers.edu> ron@topaz.rutgers.edu (Ron Natalie) writes:
>Here's a couple I wrote for the 5R2 Bourne Shell:
>I don't set the prompt to the directory names because I find it
>disgusting, but you can do that by doing PS1="$DIRSTACK" in both
>popd and pushd.
>

I thought I might post mine too.

                //-n-\\					Naoto Kimura
        _____---=======---_____				(csun!abcscnuk)
    ====____\   /.. ..\   /____====
  //         ---\__O__/---        \\	Enterprise... Surrender or we'll
  \_\                            /_/	send back your *&^$% tribbles !!
-----------------------------------------------------------------
DIRSTAK=""

dirs() {
   echo `pwd` $DIRSTAK
}

listhead() {
   echo $1
}

listtail() {
   shift
   echo $*
}

pushdir() {
   if test $# -eq 0
   then
      if test "$DIRSTAK" = ""
      then
         echo "directory stack empty." >&2
         return 1
      else
	 OLDPWD=`pwd`
         popdir
         DIRSTAK="$OLDPWD $DIRSTAK"
      fi
   else
      while test "$*" != ""
      do
	 OLDPWD=`pwd`
         if cd "$1"
         then
            DIRSTAK="$OLDPWD $DIRSTAK"
         fi
         shift
      done
   fi
}

popdir() {
   if test $# -ne 0
   then
      echo "No parameters allowed with popdir" >&2
      return 1
   else
      if test "$DIRSTAK" = ""
      then
         echo "directory stack empty." >&2
         return 1
      else
         TMP1=`listhead $DIRSTAK`
         DIRSTAK=`listtail $DIRSTAK`
         if test "$TMP1" != ""
         then
            cd "$TMP1"
         fi
      fi
   fi
}

pushd() {
   if pushdir $*
   then
	dirs
   fi
}

popd() {
   if popdir $*
   then
	dirs
   fi
}

lwv@n8emr.UUCP (Larry W. Virden) (02/12/88)

The first question is a 'technique' question.  I would like to have a series
of aliases, etc initialized for each interactive shell that I invoke (whether
it is under a terminal, pseudo terminal, etc.).  I would like to have a SUBSET
of these aliases in effect for each korn shell command that I execute.

I cannot look to see if stdin is a tty, since this is true if I execute a
ksh command without redirecting stdin - right or wrong?  I tried looking at
PPID but pseudo ttys and subshells within  my login shell, screen commands, etc.
all get messed up.  If there isnt any easy way, doesnt it seem like there SHOULD
be?

The next question is probably  just a hack by someone, but I dont really know
how to start.  I am looking for a public domain program which would allow me
to expand arguments in the same manner as the csk {} metacharacters work.  For
instance, in csh, if one says "wc -l ab{bc,de}x" you get "wc -l abbcx abdex".
I would like to have this, and if possible, something like ab{a-z}.  Note
that the difference between this and ab[a-z] is that the second expands only
to those names which exist.  The first would expand to ALL of the letters in
the range for instance, whether they exist or not.  This would make generation
of unique alphabetic file names easier, as well as some other applications
that I would like to have.

The two preferred ways of getting this would be a) as ksh hacks, or b) as a
ksh function.  A separate program would be okay, though the overhead might be
too much.

Finally, anyone know of some patches to cause the following two ksh glitches
to go away:
a) When I log into my home system, I often get the following message:       
ksh: : invalid identifier

the .profile terminates and I get the ksh prompt.  Note that the lsat things
being done were simple assignments i=/abc/xyz ; export i and so forth.

b) I have an alias r 'fc -e -' which I use to rerun previous commands.  When I want
to do argument replacemetn (which I consider to be one of the few substandard
parts of ksh) I can only substitute for strings which begin with alphabetics.
I cannot for instance say r tail +10=+20 - I get an error which says +10=+20
not found.
-- 
Larry W. Virden	 75046,606 (CIS)
674 Falls Place, Reynoldsburg, OH 43068 (614) 864-8817
cbosgd!n8emr!lwv (UUCP) 	cbosgd!n8emr!lwv@PSUVAX1 (BITNET)
We haven't inherited the world from our parents, but borrowed it from our children.

ekrell@hector.UUCP (Eduardo Krell) (02/15/88)

In article <437@n8emr.UUCP> lwv@n8emr.UUCP (Larry W. Virden) writes:
>
>The first question is a 'technique' question.  I would like to have a series
>of aliases, etc initialized for each interactive shell that I invoke (whether
>it is under a terminal, pseudo terminal, etc.).  I would like to have a SUBSET
>of these aliases in effect for each korn shell command that I execute.

The ksh variable $- contains all the flags supplied to the shell when it was
invoked or by using the set command. All interactives shell have the -i
flag set, so you can put in your ENV file:


case $- in
	*i*)	... stuff for interactive shells ...
esac
    
    Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

    UUCP: {ihnp4,ucbvax}!ulysses!ekrell		ARPA: ekrell@ulysses.att.com