lecture9 - What is a Bash Script? Conditionals Arguments...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: What is a Bash Script? Conditionals Arguments Lecture 9: Intro to Bash Scripting CS2042 - UNIX Tools October 20, 2008 Lecture 9: Bash Scripting What is a Bash Script? Conditionals Arguments Intro to Scripts Simple Examples Command Substitution Lecture Outline 1 What is a Bash Script? Intro to Scripts Simple Examples Command Substitution 2 Conditionals Tests If/Then/Else 3 Arguments Accessing Args Lecture 9: Bash Scripting What is a Bash Script? Conditionals Arguments Intro to Scripts Simple Examples Command Substitution Scripting 101 Definition: A script is very similar to a program, although it can only be run within a certain context. In other words, it cant run on its own like a program can. Shell scripts are scripts designed to run within a command shell like bash . Scripts are written in a scripting language, like perl or ruby or python. They are then run using an interpreter. In our case, the scripting language and the interpreter are both bash . Lecture 9: Bash Scripting What is a Bash Script? Conditionals Arguments Intro to Scripts Simple Examples Command Substitution The Shebang All of the shell scripts well see in this course begin the same way: with a shebang ( #! ). This is followed by the full path of the shell wed like to use as an interpreter: /bin/bash . Example: #! /bin/bash # This is the beginning of a shell script. Any line that begins with a # (except the shebang) is a comment. Comments are ignored during execution - they serve only to make your code more readable. Lecture 9: Bash Scripting What is a Bash Script? Conditionals Arguments Intro to Scripts Simple Examples Command Substitution Setting Variables Creating and setting a variable is this easy: Example: MYVAR=A new variable! Our new variable MYVAR can now be accessed as $MYVAR : Example: echo $MYVAR A new variable! Note that there are no spaces around the equals sign when you set a variable - this is important! Lecture 9: Bash Scripting What is a Bash Script? Conditionals Arguments Intro to Scripts Simple Examples Command Substitution Lecture Outline 1 What is a Bash Script? Intro to Scripts Simple Examples Command Substitution 2 Conditionals Tests If/Then/Else 3 Arguments Accessing Args Lecture 9: Bash Scripting What is a Bash Script?...
View Full Document

This note was uploaded on 01/23/2009 for the course CS 2042 taught by Professor Mccourt during the Fall '08 term at Cornell University (Engineering School).

Page1 / 23

lecture9 - What is a Bash Script? Conditionals Arguments...

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

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