Part 1: New Linux Techniques Create and execute a script file




Download 36.92 Kb.
bet2/10
Sana15.03.2017
Hajmi36.92 Kb.
#53
1   2   3   4   5   6   7   8   9   10

Part 1: New Linux Techniques

Create and execute a script file


Note: the instructions say to use vi as your editor. Substitute your version of vi (vim or vim-tiny) as needed.

A script file is basically a small, low level program. The commands in the script file are executed by the shell (bash in this lab). Scripts are handy to automate tasks. Some of the things that can be done by a script:



Useful information:

  • Parameters passed to a script are denoted by $1, $2, $3, … where $1 is the 1st parameter, $2 is the 2nd, etc.

    • The number of parameters is $#

  • Conditionals are done by an if…elif…else…fi structure

    • The if and elif are followed by a command that evaluates to true or false

    • The elif and else are optional

      • elif can be repeated

      • Only one else may be used, if needed

    • The if is closed with the fi statement

    • To stop a script use exit n

    • If a value needs to be checked the test command is used

      • Numbers use conditionals like –gt, -lt, and -eq (greater than, less than, equal)

        • E.g. test 1 –gt 2

      • Strings use = or != (equal and not equal)

    • There are other comparisons that can be done, check the internet

  • Variables are case sensitive, and are UPPER case by convention for environment variables

Download 36.92 Kb.
1   2   3   4   5   6   7   8   9   10




Download 36.92 Kb.

Bosh sahifa
Aloqalar

    Bosh sahifa



Part 1: New Linux Techniques Create and execute a script file

Download 36.92 Kb.