Some useful variables and settings in the Korn Shell
Archive - Originally posted on "The Horse's Mouth" - 2008-05-30 08:25:32 - Graham EllisHere are some hidden "gems" ...
• -C sets "noclobber" mode in which redirects do not overwrite files
$ set -C
$
$ ls > fred
$ ls > fred
ksh: cannot create fred: File exists
$ set +C
$ ls > fred
$
• CDPATH lets you change the target for your cd command to a list of directories whihc are searched in turn.
$ CDPATH=/etc:/bin
$ pwd
/home/trainee/sefas/f
$ cd
$ pwd
/home/trainee
$ cd init.d
/etc/init.d
$
• OLDPWD remembers where you were last in ksh, and cd - takes you there
$ pwd
/home/trainee
$ echo $OLDPWD
/etc/init.d
$ cd -
/etc/init.d
$
• Korn Shell - elapsed seconds, and a randon number between 0 and 32767
$ echo $SECONDS
14294
$ r
echo $SECONDS
14297
$ r
echo $SECONDS
14299
$ r
echo $SECONDS
14301
$ echo $RANDOM
28369
$ r
echo $RANDOM
5877
$ r
echo $RANDOM
28995
$