Bash basics

Environmental variables
— are in all caps. E.g HOME, USER
— the set command displays all the environmental variable
Getting the value of an environmental variable:
1. echo $HOME — note the $ as the first character
2. set | grep HISTFILESIZ

Shell (local) variables:
— simply assign a value to a name. E.g. name=Chris Note NO SPACES around the equal sign!!
— To display variable content: echo $name
data_file= data/somefile.csv
head -n 1 $data_file — displays the first line in the file

Bash allows the use of the following for loops:
— for and while
For loop format:
for line in file
do
echo $line
done

The above cam be written: for name in Tom Harry Jane; do echo $name; done — NOTE: the semi-colon after each statement. The do/done are KEY words
Wild cards can be used. E.g. for filename in data/*.csv; do echo $filename; done

File manipulation
— View a file content
— head data/filename.csv — displays the first 10 (default) lines
head -n 1 filename.csv — displays the first line

— tail data/fielname.csv — displays the last 10 (default) lines
— tail -n 1 data/filename.csv — displays the last line

— head -n15 filename.csv | tail -n 5 — passes the first 15 lines of the file to the tail command which in turn displays lines 11 to 15

— cat filename — displays the entire contents of the file to the screen
— more/less filename — allows you to page thru the contents of the file

— cut d, -f 2-5, 8 filename.csv — displays selected columns from a file:
— d, = delimiter comma (space is default)
— f 2-5,8 -d = fields (columns) to display — columsn: 2 thru 5, and 8
— doesn’t understand quoted strings