06-lec-shellscripting - Shell Scripting Intermediate...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Shell Scripting Intermediate Systems Administration DeCal Lecture #6 Michael Gasidlo
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Today Unlock the raw power of the shell as a programming language! How to use variables + special variables How to create functions Control structures: for, while, if, case Input functionality with read, shift Shell builtins: echo, printf , let, test (aka [ )
Background image of page 2
Shell scripts At their simplest, just a list of commands executed in order as if you had typed them into the shell. Anything you can do at the shell, you can do in a shell script, and vice versa. Like DOS batch scripts, but way better . Run them by putting “#!/bin/sh” at the top and using chmod +x to make executable.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variables Assignment: FOO=“Test 1 2 3” Reference: echo $FOO or echo “$FOO” (What’s the difference?) Want to set a variable to the output of a command? Input substitution! FOO=$(ls pictures)
Background image of page 4
Special Shell Variables $1, $2, $3 .. - arguments passed in on command line. $@ - all arguments as a big string. $# - number of arguments passed in $? - exit code of last program; you knew this already $$ - your process ID $! - process ID of last program started w/ ‘&’
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Functions When you make a shell script, lines of code are executed top-to-bottom If you make functions, they won’t be run
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/14/2010 for the course CS 161 taught by Professor Wagner during the Spring '10 term at University of Central Arkansas.

Page1 / 16

06-lec-shellscripting - Shell Scripting Intermediate...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online