1 / 8

Writing Scripts: The Basics

Writing Scripts: The Basics. David Douglas & Peggy L. Lane. Shell Script. A program written to automate a process in the Linux operating system. Written in an editor. What can a script do?. Make decisions based upon conditions. Perform arithmetic operations.

byron-pena
Télécharger la présentation

Writing Scripts: The Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Writing Scripts: The Basics David Douglas & Peggy L. Lane

  2. Shell Script • A program written to automate a process in the Linux operating system. • Written in an editor.

  3. What can a script do? • Make decisions based upon conditions. • Perform arithmetic operations. • Create a menu using looping statements. • Use functions to perform very specific tasks. • Manipulate data using an array (like a table).

  4. How do I create a script? • Ensure you are in your home directory. • Type jpico and press enter. • This will place you in edit mode and it will look like this:

  5. Creating and Running a script • Enter the script (more on this later). • Press Ctrl-X (^X) to Exit the editor and Save the script. • When prompted, enter the name of the script and press enter. • To run the script, type sh filename and press the enter key. • (filename is the name of the script.)

  6. Creating a Simple Script • Assume you want to create a script that you will run to display the following information after logging in: • Current date and time • Pathname of the current working directory • Who else is currently on the system • To begin, type jpico start and press enter • To include comments, place # in front of the text. • What commands will provide the 3 pieces of information listed above? • Type the following…….

  7. My First Script!! • #This is my startup batch file that performs • #three functions. It provides me with the date • #and time, the current working directory, • #and the login names of anyone else who is on • #the system. The good news is that the • #backspace key works in the editor!! • date • pwd • who

  8. Next Steps • To exit the editor, press Ctrl-X • You will see a prompt • If you typed jpico without a filename, you will be prompted for a filename. Enter start. • If you provided the filename of start, you will see: Name of file to save (^C to abort): start • Press the enter key. • Type sh start and press the enter key to run the script.

More Related