![]() ![]() ![]() : # if you're not doing anything, you must put : here : # use double quotes if variable can be empty : # -ge greater than equal to, -le less than equal toĮlif then # text comparison : # blank or text in variable will cause this to failĮlif then # -gt greater than, -lt less than, tr # reads the input, does character substitution based on first two parameters, sends to outputĬonditional Flow Control if then # integer equivalence comparison only.sed supports basic regex and with the -E switch, more extended regex features.sed s/search/replace/g # replace all instances of “search” with "replace.sed s/search/replace/ # replace the first instance of “search” with “replace”.if parameter 2 is defined, read from file instead of input stream sed # reads input stream, does substitution based on parameter 1 regex, sends to output stream.“ hello_copy.txt # reads contents of hello.txt and redirect the output to file hello_copy.txt.if the file does not exist, create it.echo “ef” > hello.txt # appends “ef” to a file named hello.txt.“>” “redirect append to file” appends stream of the left program to the file on the right.echo “abc” > hello.txt # sends “abc” to a file named hello.txt.“>” “redirect to file” sends the output stream of the left program to the file on right.echo “abc” | sed s/b/d/ # send “abc” to sed and replace b with d, “adc”.“|” “pipe” connects the output stream of the left program to the input of the right program.Error is another stream like output but for errors and other messages not wanted in the output.īash has a few ways to manipulate streams:.For echo, it is the content being printed. Output is the stream coming out of your program.Input can be your keyboard, or stream coming out of another program.Why use double quotes? b=$a b # two or more whitespace characters collapse into one, "1 b"Ī='$a b' #preserves whitespace and does not allow substitution, "$a b"Ī="$a b" #preserves whitespace and allows substitution, "1 b" a=1 # string "1"Ī='1' # single quotes prevents substitution of variablesĪ="1" # double quotes allow substitution of variablesĮcho $a # prints 1 with a new line to output streamĮcho '$a' # prints $a with a new line to output streamĮcho "$a" # prints 1 with a new line to output stream Variables are string type except when they are arrays or maps. ioctl’s # IO controls is for device control which is beyond the scope of this doc. ![]() filesystem read and write access # the everything is a file unix philosophy.IO Streams # usually have 3 streams, input, output, and error but can have more.Parameters # echo “abc” “ef” where echo is the 0th parameter, abc is the 1st, ef is the 2nd.Programs or executables are scripts or binaries that perform actions. Consume at your own risk.Įverything after a # sign except within the context of a quote or double quote This is a quick and dirty guide for bash and Linux with some must understand concepts. ![]()
0 Comments
Leave a Reply. |