Download presentation
Presentation is loading. Please wait.
1
CIRC Summer School 2016 Baowei Liu
Bash Scripting CIRC Summer School 2016 Baowei Liu
2
Day 3 Examples ssh to bluehive cd your directory for this class
./shareFiles.sh Day3
3
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
4
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
5
I/O Redirection: Pipes
Pipes connect the standard output of one command to the standard input of another with the pipe symbol |. command1 | command2
6
Filename Expansion / Globbing
Expanding filenames containing special characters Wild cards * ? Square brackets [set]: “-” Special characters: ! (other than) Escaping backslash: protect a subsequent special character
7
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
8
Regular Expression Regular Expression: globbing pattern used for text
. : Equivalent to ? in filename expansion .*: any string. Equivalent to * in filename expansion * : zero or more times, a* will match a,aa,…but not ab ^: starting with, ^ab $: ending with, ab$
9
Regular Expression []: “-” \< \>: exact word
10
sed and Regular Expressions
Stream editor for parses and transform text sed ‘s/abc/xyz’ File: All 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
11
Project Write a Bash script to black out sensitive information buried in the files under files/ ./shareFiles.sh finalProject Key tech: editor, chmod, command substitution, for loop, echo, sed, regular expression, i/o redirection
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.