OS and shell script programming
operating system: the software that supports a computer’s basic functions. os has control over application programs. os is our first interface (computer system -> os). BIOS selects which code to start running based on a priority over bootable media. BIOS can load an OS and begin its execution. The kernel is the part of an OS that runs first, it’s responsible for loading specifications/running all other programs. (Hardware -> Kernel -> applications)
shell: command interpreter thatturns texts into actions, runs a program/commands such as $ls -l /bin (here ls is program name, -l and /bin are arguments.
Shell Script programming: it involves listing several shell commands in order, perhaps with the input/output redirection and pipe operators to make them work together. shell programs are written in text files named .bash by convention. it is proper shell programming practice to add a shabang, #!/bin/bash to indicate which shell we use. we’ll use vim. learn the shortcuts.
shell conditions: if
if program then commands fi: every process returns an integer value when it terminates. this is part of the linux process specification. ex)ls returns 0 when the file you ask it to list was present, otherwise it returns false. it checks the return code from a program y accessing the special shell variable “?”
for i in this is a test (for variable in wordlist do stuff done
do echo $i done //this prints this is a test
while program < check return code of program
do list_of_commands <Execute the whole list each time
commands<“”<$(prefix for var name) , \x, <’’ (single case different from back tick character_
? matches any single character, ex) ls Test?.doc
ls T[eE][sS].doc ls [a-zA-Z]* matches any character in a range. ls[!0–9] any except those listed.
ls -al * //long liste * replace it with all the filenames in the current directory. a*b matches all files in the current directory that starts with a and end with b
/ : root of the file. ls ~/ : current users home directory.
. : right here when it starts a path, ls /usr/./bin
.. : parent directory, cd ..
The shell allows you to manage jobs, place jobs in the background/ move a job to the foreground/ suspsend a job/kill a job. Background jobs: ls -lR > saved_ls &
jobs: to list background jobs. To foreground jobs, fg %1. fg a job number preceeded by a %.