ksh & command line interpretation

ksh & command line interpretation

Post by Heather Wile » Sat, 14 Jun 1997 04:00:00



in the book "Unix SystemV Release4 An Intoduction" by Ken Rosen,Richard
Rosinski and James Farber there is a script called ksh.preamble as
follows:
        if [x"$RANDOM" = x"$RANDOM"]
        then

                exit "$?"
        fi

couple of questions
 (1)what is the phrase x"$RANDOM"

 (2)how does the shel expand/interpret the line

thanks

 
 
 

ksh & command line interpretation

Post by Allen Kirb » Sat, 14 Jun 1997 04:00:00



> in the book "Unix SystemV Release4 An Intoduction" by Ken Rosen,Richard
> Rosinski and James Farber there is a script called ksh.preamble as
> follows:
>         if [x"$RANDOM" = x"$RANDOM"]
>         then

>                 exit "$?"
>         fi

> couple of questions
>  (1)what is the phrase x"$RANDOM"

>  (2)how does the shel expand/interpret the line

> thanks


Heather,
$RANDOM is a ksh builtin random number generator. Each reference to
$RANDOM will return a different number.  Therefore, in ksh $RANDOM
will never equal $RANDOM (the x is added because in a non-ksh script
$RANDOM probably won't be defined and you could get an error from
the test operator due to missing arguments).  So, if x$RANDOM DOES
equal x$RANDOM, you aren't running ksh, so this example will execute
ksh to re-execute the current script, with existing arguments preserved.

--
Allen Kirby                     AT&T ITS Production Services


 
 
 

ksh & command line interpretation

Post by Donn Ca » Sat, 14 Jun 1997 04:00:00


| in the book "Unix SystemV Release4 An Intoduction" by Ken Rosen,Richard
| Rosinski and James Farber there is a script called ksh.preamble as
| follows:
|       if [x"$RANDOM" = x"$RANDOM"]
|       then

|               exit "$?"
|       fi

Do be careful with [.  The above will fail because you left out the
white space after [, and before ].  "[" is another way to spell "test",
a fraudulent and only partly successful attempt to simulate a
syntactical feature of other languages.  The "case" command avoids
this nonsense and does a better job with string comparisons.

| couple of questions
|  (1)what is the phrase x"$RANDOM"

The Korn shell generates a random number on reference to this variable,
each time, so it won't equal itself - if it's ksh.  That's the question.

|  (2)how does the shel expand/interpret the line

Well, it doesn't, but if you swap ` for ', it will determine the full
path to the current script and run ksh on itself.  Also see "exec",
which the authors probably should have used, and see if you can find
what the default value for "exit" is, if no parameter is supplied.

        Donn Cave, University Computing Services, University of Washington

 
 
 

ksh & command line interpretation

Post by Ralf Fasse » Sun, 15 Jun 1997 04:00:00


| [Date: Fri, 13 Jun 1997 11:54:49 -0400]

|   >         if [x"$RANDOM" = x"$RANDOM"]
--<snip-snip>--
|   ...  (the x is added because in a non-ksh script $RANDOM probably won't
|   be defined and you could get an error from the test operator due to
|   missing arguments).

(Warning: nitpick ahead)
Strictly spoken, the x is not necessary when there are "" double quotes
around the variable reference:
   if ["$RANDOM" = "$RANDOM"]
should work as well (apart from the syntax error, see below) in any sh-like
shell, though you need the x if you go
   if [x$RANDOM = x$RANDOM]

*BUT* there should be a space after the `[', like this
  if [ x"$RANDOM" = x"$RANDOM" ]
otherwise it won't work at all

  UX:sh (t): ERROR: [x: Not found
  t[7]: [x24007:  not found

Regards
R'
--
Enter any 11-digit prime number to continue...

 
 
 

1. ksh: 2 Q's, command completion & command history?

Hi all,

Command completion in ksh is done with Esc Esc (hitting the escape key
twice). Although I've never been successful at getting this to work on
my system at work (AIX 3.2.5), I read that's the key sequence for
command/path completion.

My question is, can that be changed to the Tab key and if so how, in
ksh? Command completion in tcsh and bash use the Tab key. The Tab key is
SO MUCH MORE convenient a key for command completion.

Another question... about previous command retrieval. bash and tcsh use
the UP and DOWN arrow keys for command retrieval. ksh uses Esc-k & Esc-j
respectively. UP & DOWN are MUCH BETTER choices. Can this be changed in
ksh and how?

Any guidance would be appreciated. I like the ksh for it's better (I
think so) scripting/programming features but the way it implements
command/path completion and previous command retrieval is really
annoying me. So much time can be saved with the use of Tab and UP,DOWN
keys.

Thanks, Zoran.

2. data breakpoint kernel support ?

3. what is the maximum size of command line on KSH ?

4. which desktop should i use

5. increase ksh command line length?

6. Missing Xm.h for Mosaic on Linux

7. Using ksh command line edit as Superuser in Solaris

8. screenblank

9. ksh Filename Completion using vi command line editing mode?

10. ksh:edit command line

11. ksh not evaluating if in shell, but works in command line

12. command line completion in ksh

13. Ksh: Command line editing with arrow keys?