UNIX CODE (Korn Shell):


General TIPS:
  o Unix IS "case SeNsItIvE".
  o The GRAVE symbol (`) is USUALLY on the same key as the TILDE (~).
  o BRACES   refer to { and }.
  o BRACKETS refer to [ and ].
  o SEMICOLON (;) allows MULTIPLE commands on ONE line.
  o POUND (#) says "comments follow"'
    o Use #d# for Self Documenting using   grep "#d#" filespec
  o Run via    ksh filespec optional_parameter(s)
    o There can be up to 9 parameters (0 is the filespec)
  o If you are manipulating items with \ involved such as dos type directories,
    o use  "read -r"  in place of "read"  ("-r" meand Raw data)
    o use  "print -r" in place of "echo"  ("-r" meand Raw data)
  o String comparisons use "=", "!="
  o Numerical comparisons use -eq -ne -gt -lt -ge

# Seeing if ANY parameters were passed
 IZP1=$1                         # $1 is reserved for first parameter
 if [ "$IZP1" != "" ] ; then     # the "!=" means NOT EQUAL; use -ne for numerics
   echo "Parameters WERE passed"
 else
   echo "NO passed parameters"
 fi


# READING AN EXISTING FILE BOOK=/usr/randy/sample.txt # BOOK is a SYMBOL for /usr/randy/sample.txt ICT=0 ; LCT=1 # ";" continues (these COULD be on separate lines) NOL=`wc -l $BOOK` # the ` is the GRAVE symbol until [ $LCT = $NOL ] # UNTIL line counter LCT same as Number of lines NOL do # DO the following ((ICT=$ICT+1)) # NO SPACES; steps up ICT by 1 LIN=`sed -n ${LCT}p $BOOK` # read line #LCT into LIN note: graves and braces {} # Put HERE what to DO with the LINE symbol $LIN # ie: if the line were "This is obviously a test", to get the # the THIRD word delimited by a space, enter: # WORD3=`echo $LIN | cut -d" " -f3` ((LCT=$LCT+1)) # NO SPACES; steps up LCT by 1 done

# Getting user input into symbol named "$VAL" echo "::: Enter a value: \c" # the "\c" keeps the cursor on SAME line as the query read VAL # I like to keep the "read" on SAME line as "\c"

# Creating a NEW file NUFIL=/usr/randy/nuexample.txt echo "This is LINE number ONE" >$NUFIL # Creates NEW (exists OR not) echo "NOW add SECOND line" >>$NUFIL # Add to file

# Extracting value from Environment (see what value for "editor") WHATIS=`alias | grep -i editor` # The "-i" ignores case of "editor" echo "Value found is ($WHATIS)" # output to screen

Return to Randys HOME PAGE
Created Mar 04, 1996 ~ Updated: Aug 09, 1996
© 1996 R.D.RISHER