Command Line Processing

Command Line Processing

Command Line Processing By High School Technology Services myhsts.org Recap From Previous Session In previous session we learned . We covered – ▪ Process Ownership ▪ suid and sgid ▪ Restricted Shells ▪ Other Security Features ▪ The newgrp Command ▪ Statement blocks ▪ case Statement Outline ▪ Getting Data Into Scripts ▪ Manipulating Positional Parameters (set, sort, shift) ▪ Analyzing Switches with getopts ▪ Options ▪ Reserved Variables (OPTARG, OPTIND, IFS) ▪ Setting Default Values Getting Data Into Scripts echo Hello, who am I talking to? read varname echo It\'s nice to meet you $varname Manipulating Positional Parameters (set, sort, shift) set is a built-in function of the Bourne shell (sh), C shell (csh), and Korn shell (ksh), which is used to define and determine the values of the system environment. set [+-aefhkmnopstuvx] [+-o option]... [+-A name] [arg...] https://www.computerhope.com/unix/uset.htm Manipulating Positional Parameters (set, sort, shift) sort is a simple and very useful command which will rearrange the lines in a text file so that they are sorted, numerically and alphabetically. By default, the rules for sorting are: Lines starting with a number will appear before lines starting with a letter. Lines starting with a letter that appears earlier in the alphabet will appear before lines starting with a letter that appears later in the alphabet. Lines starting with a lowercase letter will appear before lines starting with the same letter in uppercase. https://www.computerhope.com/unix/usort.htm Analyzing Switches with getopts When you want to parse command line arguments in a professional way, getopts is the tool of choice. Unlike its older brother getopt (note the missing s!), it's a shell builtin command. The advantages are: No need to pass the positional parameters through to an external program. Being a builtin, getopts can set shell variables to use for parsing (impossible for an external process!) There's no need to argue with several getopt implementations which had buggy concepts in the past (whitespace, …) getopts is defined in POSIX®. Reserved Variables (OPTARG, OPTIND, IFS) The base-syntax for getopts is: getopts OPTSTRING VARNAME [ARGS...] where: OPTSTRING tells getopts which options to expect and where to expect arguments (see below) VARNAME tells getopts which shell-variable to use for option reporting ARGS tells getopts to parse these optional words instead of the positional parameters Looking Forward In the next session we will . We’ll cover - ▪ Improving the Performance of Scripts ▪ Timing Commands and Scripts ▪ System Resources ▪ Setting Limits ▪ Portability Issues Thank You. By High School Technology Services myhsts.org.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us