FIT3042 Lecture Notes - Lecture 17: Chmod

30 views2 pages
L17: Scripting with Bash
Unix Command shells
Bash - not a user interface. It's a programming language interpreter
What is a script?
Put a list of commands that might tye at a bash prompt into file
Execute that file
Commands will run
Simple example:
Running a script
First way
Make it executable ( with chmod +x) and then run it like an ordinary executable : ./myfile.sh
Makes a new bash process which will interpret myfile.sh
Second Way
Use the source command: source myfile.sh
Tells current bash to interpret myfile.sh
Good to use if you want to change environment variables in your current shell
Variables
= : set
$ : access
“ “ : needed around string that contain spaces. Variable substuon
‘ ‘ : don't do variable substuon
* : matches any sequence of character
? : matches any one character
[ab] : matches an a or b
[a-c] : matches a, b, or c
{foo, bar} : matches the string foo or the string bar
Flow of control: if, while, case
Condional have [ ] around them
[ -e FILE ] : true if FILE exists
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Bash - (cid:374)ot a use(cid:396) i(cid:374)te(cid:396)fa(cid:272)e. it"s a p(cid:396)og(cid:396)a(cid:373)(cid:373)i(cid:374)g la(cid:374)guage i(cid:374)te(cid:396)p(cid:396)ete(cid:396) Put a list of (cid:272)o(cid:373)(cid:373)a(cid:374)ds that (cid:373)ight t(cid:455)e at a (cid:271)ash p(cid:396)o(cid:373)pt i(cid:374)to le. Make it e(cid:454)e(cid:272)uta(cid:271)le (cid:894) (cid:449)ith (cid:272)h(cid:373)od +(cid:454)(cid:895) a(cid:374)d the(cid:374) (cid:396)u(cid:374) it like a(cid:374) o(cid:396)di(cid:374)a(cid:396)(cid:455) e(cid:454)e(cid:272)uta(cid:271)le : . /(cid:373)(cid:455) le. sh. Makes a (cid:374)e(cid:449) (cid:271)ash p(cid:396)o(cid:272)ess (cid:449)hi(cid:272)h (cid:449)ill i(cid:374)te(cid:396)p(cid:396)et (cid:373)(cid:455) le. sh. Good to use if (cid:455)ou (cid:449)a(cid:374)t to (cid:272)ha(cid:374)ge e(cid:374)(cid:448)i(cid:396)o(cid:374)(cid:373)e(cid:374)t (cid:448)a(cid:396)ia(cid:271)les i(cid:374) (cid:455)ou(cid:396) (cid:272)u(cid:396)(cid:396)e(cid:374)t shell. : (cid:374)eeded a(cid:396)ou(cid:374)d st(cid:396)i(cid:374)g that (cid:272)o(cid:374)tai(cid:374) spa(cid:272)es. {foo, (cid:271)a(cid:396)} : (cid:373)at(cid:272)hes the st(cid:396)i(cid:374)g foo o(cid:396) the st(cid:396)i(cid:374)g (cid:271)a(cid:396) [ -e file ] : t(cid:396)ue if file e(cid:454)ists. [ -f file ] : t(cid:396)ue if file e(cid:454)ists a(cid:374)d is a (cid:396)egula(cid:396) le. [ -(cid:396) file ] : t(cid:396)ue if file e(cid:454)ists a(cid:374)d is (cid:396)eada(cid:271)le. [ n(cid:1005) -gt n(cid:1006) ] : t(cid:396)ue if n(cid:1005) is g(cid:396)eate(cid:396) tha(cid:374) n(cid:1006) [ n(cid:1005) -lt n(cid:1006) ] : t(cid:396)ue if n(cid:1005) is less tha(cid:374) n(cid:1006) [ n(cid:1005) -e(cid:395) n(cid:1006) ] : t(cid:396)ue if n(cid:1005) is e(cid:395)ual to n(cid:1006)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents