Presentation is loading. Please wait.

Presentation is loading. Please wait.

CIRC Summer School 2017 Baowei Liu

Similar presentations


Presentation on theme: "CIRC Summer School 2017 Baowei Liu"— Presentation transcript:

1 CIRC Summer School 2017 Baowei Liu 7.25.2017
Bash Scripting CIRC Summer School 2017 Baowei Liu

2 Stdin, stdout and stderr
File descriptor(FD): a handle to access a file Stdin: standard input stream (e.g. keyboard) –FD:0 Stdout: standard output stream (e.g. monitor) –FD:1 Stderr: standard error output stream (usually also on monitor) ) –FD:2

3 I/O Redirection: Redirecting to a file
Redirect between files including the three file descriptors, stdin, stdout and stder Redirecting output: date > file Appending redirecting output: date >> file Redirecting input: Command < input

4 I/O Redirection: Pipes
Pipes connect the standard output of one command to the standard input of another with the pipe symbol |. command1 | command2

5 Positional Parameters
Arguments given to bash script when it is invoked $1, $2 … $N. ${N} if N>9 $0 is the base-name of the script $# is the total arguments given Example: shareFiles.sh positionalParameters.sh

6 grep grep: search for matches to a pattern in a file and print the matched line to stdout grep Pattern file Pattern could be simple strings or regular expressions

7 Regular Expression Regular Expression: globbing pattern used for text
. : Equivalent to ? in filename expansion * : zero or more times, aa* will match a,aa,…but not ab .*: any string. Equivalent to * in filename expansion ^: starting with, ^ab $: ending with, ab$

8 Regular Expression []: “-” \< \>: exact word

9 sed and Regular Expressions
Stream editor for parses and transform text sed ‘s/abc/xyz/’ File: first occurrences sed ‘5,10s/abc/xyz/’ File: range, specified lines Sed ‘0~2 s/abc/xyz/’ File: Every other line starting 0 or even lines

10 sed and Regular Expressions
Word Characters: Alphanumeric characters plus “_” [A-Za-z0-9_] Replace all occurrences in a line

11 More Examples Wrappers

12 Project Write a Bash script to black out sensitive information buried in all but the .data files under files/ (i.e. ONLY the html,xml,txt files) Key tech: editor, chmod, command substitution, for loop, echo, case/if, string compare, substring remove, sed, regular expression, i/o redirection


Download ppt "CIRC Summer School 2017 Baowei Liu"

Similar presentations


Ads by Google