SlideShare a Scribd company logo
CIS 216 Unix Scripting
Highline Community College
        Dan Morrill
 When working with case you want to read input:
   read choice
   cd $choice
      This reads the input from the keyboard and then changes the
       directory over to the one specified by the user. Choice is
       read, and then used as a variable
 You can do this anywhere in a script for just about any
 thing you can do on a Linux Box
   read UserProcess
   ps –ef |grep $UserProcess
1.   FRUIT="kiwi"
2.   case "$FRUIT" in
3.     "apple") echo "Apple pie is quite tasty."
4.     ;;
5.     "banana") echo "I like banana nut bread."
6.     ;;
7.     "kiwi") echo "New Zealand is famous for kiwi."
8.     ;;
9.   esac
 In this program we see Fruit is set = “kiwi”
 The case statement reads the $Fruit and where there is
  a match, in this case kiwi, outputs the text:
 New Zealand is famous for kiwi


 If we wanted to change this so that user input was
  considered we would change:
   Read Fruit
   echo “allowed entries are apple, banana, and kiwi”
   remember case sensitivity.
 choiceA || continue
 If no conversion needs to be done, a continue
 statement restarts execution of the loop.
   the “||” = to a logical OR
   [ “$choiceA] or continue
 The tput utility uses the terminfo database to make
 the values of terminal-dependent capabilities and
 information available to the shell, to initialize or reset
 the terminal, or return the long name of the requested
 terminal type. tput outputs a string if the attribute
 (capability name) is of type string, or an integer if the
 attribute is of type integer. If the attribute is of type
 boolean, tput simply sets the exit code (0 for TRUE if
 the terminal has the capability, 1 for FALSE if it does
 not), and produces no output.
1. case $RCOUNT in
2.   1) tput cup 2 0; echo -e "- L.    bc"
3.     sleep $INTERVAL
4.     ;;

 Case using a counting variable $RCOUNT
 TPUT CUP (Position the cursor on the screen to XY 2
  and 0 echo the letter L
 Sleep for the variable $INTERVAL
 To change the color of the text, use the setb option for setting the
    background color and the setf option for setting the foreground
    color along with the number of the color assigned in the
    terminfo database. The following numbers and colors are
    typically assigned but may vary from each UNIX system:
   0: Black
   1: Blue
   2: Green
   3: Cyan
   4: Red
   5: Magenta
   6: Yellow
   7: White
 tput cup 2 0; echo -e " Lo..        bc“
 To
 tput setf 4 cup 2 0; echo -e " Lo..         bc“

 To have a foreground color of Red
 setf = foreground color
 setb = background color
   This is bad for people who are color blind and not using
       the standard terminal coloring
1.    INTERVAL=1000 # Sleep time between rotation intervals
2.    RCOUNT="0" # For each RCOUNT the line rotates 1/8
3.         # cycle

4.    while : # Loop forever...until this function is killed
5.    do
6.      (( RCOUNT = RCOUNT + 1 )) # Increment the RCOUNT

7.      case $RCOUNT in
8.      1) tput cup 2 0; echo -e "- L.      bc"
9.        sleep $INTERVAL
10.       ;;
11.     2) tput cup 2 0; echo -e " Lo..    bc"
12.       sleep $INTERVAL
13.       ;;
Understanding UNIX CASE and TPUT

More Related Content

DOC
Laboratory activity 3 b1
PPTX
Scripting ppt
PPTX
Bs7799
PDF
Tiling and Zooming ASCII Art @ iOSoho
PPTX
Windows power shell and active directory
PDF
Linux Command Line Introduction for total beginners, Part 2
PPTX
PPTX
Intro to OpenMP
Laboratory activity 3 b1
Scripting ppt
Bs7799
Tiling and Zooming ASCII Art @ iOSoho
Windows power shell and active directory
Linux Command Line Introduction for total beginners, Part 2
Intro to OpenMP

Similar to Understanding UNIX CASE and TPUT (20)

PDF
If You Think You Can Stay Away from Functional Programming, You Are Wrong
DOCX
PERL for QA - Important Commands and applications
PPTX
Licão 12 decision loops - statement iteration
PDF
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
PDF
php_string.pdf
PPTX
Load-time Hacking using LD_PRELOAD
PPTX
Shell scripting
PPTX
An introduction to Raku
PDF
The swift programming language
PPTX
Unix Shell Programming subject shell scripting ppt
PPT
ch08.ppt
PDF
Perl_Part2
PPT
CPAP.com Introduction To Coding: Part 2
PDF
PDF
Advanced perl finer points ,pack&unpack,eval,files
PPTX
Matlab Script - Loop Control
PPT
Introduction to perl scripting______.ppt
PPT
Shell Scripting
PDF
CLISP Lab Manual - Dr.J.VijiPriya
PPTX
C programming language tutorial
If You Think You Can Stay Away from Functional Programming, You Are Wrong
PERL for QA - Important Commands and applications
Licão 12 decision loops - statement iteration
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
php_string.pdf
Load-time Hacking using LD_PRELOAD
Shell scripting
An introduction to Raku
The swift programming language
Unix Shell Programming subject shell scripting ppt
ch08.ppt
Perl_Part2
CPAP.com Introduction To Coding: Part 2
Advanced perl finer points ,pack&unpack,eval,files
Matlab Script - Loop Control
Introduction to perl scripting______.ppt
Shell Scripting
CLISP Lab Manual - Dr.J.VijiPriya
C programming language tutorial
Ad

More from Dan Morrill (18)

PPTX
Windows power shell basics
PPTX
Understanding web site analytics
PPTX
Process monitoring in UNIX shell scripting
PPTX
Creating a keystroke logger in unix shell scripting
PPTX
Information security principles
PPTX
Using Regular Expressions in Grep
PPTX
Understanding the security_organization
PPTX
You should ask before copying that media
PPTX
Cis 216 – shell scripting
PPTX
Understanding advanced persistent threats (APT)
PPTX
AWS Hadoop and PIG and overview
PPTX
What is cloud computing
PPT
Social Media Plan for CityU of Seattle
PPT
BSIS Overview
PPT
Case Studies In Social Media Chinese
PPT
Case Studies In Social Media
PPT
Turn On Tune In Step Out
PPT
Technology And The Future Of Management
Windows power shell basics
Understanding web site analytics
Process monitoring in UNIX shell scripting
Creating a keystroke logger in unix shell scripting
Information security principles
Using Regular Expressions in Grep
Understanding the security_organization
You should ask before copying that media
Cis 216 – shell scripting
Understanding advanced persistent threats (APT)
AWS Hadoop and PIG and overview
What is cloud computing
Social Media Plan for CityU of Seattle
BSIS Overview
Case Studies In Social Media Chinese
Case Studies In Social Media
Turn On Tune In Step Out
Technology And The Future Of Management
Ad

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Lesson notes of climatology university.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
102 student loan defaulters named and shamed – Is someone you know on the list?
Complications of Minimal Access Surgery at WLH
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
202450812 BayCHI UCSC-SV 20250812 v17.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
A systematic review of self-coping strategies used by university students to ...
Lesson notes of climatology university.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
GDM (1) (1).pptx small presentation for students
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Understanding UNIX CASE and TPUT

  • 1. CIS 216 Unix Scripting Highline Community College Dan Morrill
  • 2.  When working with case you want to read input:  read choice  cd $choice  This reads the input from the keyboard and then changes the directory over to the one specified by the user. Choice is read, and then used as a variable  You can do this anywhere in a script for just about any thing you can do on a Linux Box  read UserProcess  ps –ef |grep $UserProcess
  • 3. 1. FRUIT="kiwi" 2. case "$FRUIT" in 3. "apple") echo "Apple pie is quite tasty." 4. ;; 5. "banana") echo "I like banana nut bread." 6. ;; 7. "kiwi") echo "New Zealand is famous for kiwi." 8. ;; 9. esac
  • 4.  In this program we see Fruit is set = “kiwi”  The case statement reads the $Fruit and where there is a match, in this case kiwi, outputs the text:  New Zealand is famous for kiwi  If we wanted to change this so that user input was considered we would change:  Read Fruit  echo “allowed entries are apple, banana, and kiwi”  remember case sensitivity.
  • 5.  choiceA || continue  If no conversion needs to be done, a continue statement restarts execution of the loop.  the “||” = to a logical OR  [ “$choiceA] or continue
  • 6.  The tput utility uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell, to initialize or reset the terminal, or return the long name of the requested terminal type. tput outputs a string if the attribute (capability name) is of type string, or an integer if the attribute is of type integer. If the attribute is of type boolean, tput simply sets the exit code (0 for TRUE if the terminal has the capability, 1 for FALSE if it does not), and produces no output.
  • 7. 1. case $RCOUNT in 2. 1) tput cup 2 0; echo -e "- L. bc" 3. sleep $INTERVAL 4. ;;  Case using a counting variable $RCOUNT  TPUT CUP (Position the cursor on the screen to XY 2 and 0 echo the letter L  Sleep for the variable $INTERVAL
  • 8.  To change the color of the text, use the setb option for setting the background color and the setf option for setting the foreground color along with the number of the color assigned in the terminfo database. The following numbers and colors are typically assigned but may vary from each UNIX system:  0: Black  1: Blue  2: Green  3: Cyan  4: Red  5: Magenta  6: Yellow  7: White
  • 9.  tput cup 2 0; echo -e " Lo.. bc“  To  tput setf 4 cup 2 0; echo -e " Lo.. bc“  To have a foreground color of Red  setf = foreground color  setb = background color  This is bad for people who are color blind and not using the standard terminal coloring
  • 10. 1. INTERVAL=1000 # Sleep time between rotation intervals 2. RCOUNT="0" # For each RCOUNT the line rotates 1/8 3. # cycle 4. while : # Loop forever...until this function is killed 5. do 6. (( RCOUNT = RCOUNT + 1 )) # Increment the RCOUNT 7. case $RCOUNT in 8. 1) tput cup 2 0; echo -e "- L. bc" 9. sleep $INTERVAL 10. ;; 11. 2) tput cup 2 0; echo -e " Lo.. bc" 12. sleep $INTERVAL 13. ;;

Editor's Notes

  • #5: http://www.tutorialspoint.com/unix/case-esac-statement.htm
  • #9: http://www.ibm.com/developerworks/aix/library/au-learningtput/