Day 35: Finally Breaking down .dotfiles

I moved on to Lecture 5 and it was breaking down config files and common practices for customizing programs.

TLDR;

Okay, so here are the highlights of what I did:

  • I watched the YouTube recording of lecture 5 of the MIT Missing Semester Course. It covered running multiple processes from the terminal using Tmuxt and shell commands. It also covered ssh and .dotfiles which was very useful.
  • I continued with my notes on the awk programming language. The manual is really in depth which I love and hate. lol
  • I started going through chapter 4 in the “Programming from the Ground Up” book by Jonathan Bartlett. Chapter 4 covers functions in assembly.

Notes from gawk manual – Expressions


6.2 Operators in awk

Arithmetic operators

awk uses most of the same math operators as other programming languages. The following list shows each operation in the order of operations (Precedence) in awk .

  • x ^ y Exponents
  • - x Neg (Unary negative)*
  • + x Pos (Unary plus)*
  • x * y multiplication
  • x / y division (all numbers in awk are floating point.
  • x % y Remainder
  • x + y addition
  • x - y subtraction

*The Unary Plus/Negative have the same precedence and when used on a string expression that string expression is converted to a number.

Also the remainder is calculated with an operation called trunc-mod. This means that the result may sometimes be negative which we must correct for so that it does not affect our calculations.

# trunc-mod formula
b * int(a / b) + (a % b) == a

# flip it
( a % b ) == a - ( b * int(a / b)

# Example a = -17 , b = 8 
( -17 % 8 ) == -17 - ( 8 * int( -17/8 ) )

# result: -1

Concatenation

There is only one operation that can be performed on strings. That is concatenation We can combine strings together with no spaces in between them by placing them space-separated inside parentheses. (They can be just placed beside each other but placing them inside parentheses guarantees that the concatenation is in fact the desired action we want happening. (Improves readability).

Assignment Ops

With assignments we can store numbers, strings, and regexp constants in variables (regexp only in gawk).

# syntax
lvalue = rvalue

The lvalue (left-hand operand) can be a variable, a field, or array element. e.g. $1 = Name . The rvalue is an expression. Additionally, all variables are loosely typed. The same variable can hold a string and then a number (Don’t do this as it’s a bad programming practice).

We can also do multiple assignment like this: x = y = z = 5.

There are also arithmetic assignment variables just like with many other programming languages:

  • lvalue += increment
  • lvalue -= decrement
  • lvalue *= coefficient
  • lvalue /= divisor
  • lvalue %= modulus Set lvalue to its remainder by modulus.
  • lvalue ^= power Raise lvalue to the power power.

Increment Ops

Increment and decrement operators increase or decrease the value of a variable by one. An assignment operator can do the same thing, so the increment operators add no power to the awk language; however, they are convenient abbreviations for very common operations.

  • ++lvalue Increment lvalue, returning the new value as the value of the expression.
  • lvalue++ Increment lvalue, returning the old value of lvalue as the value of the expression.
  • --lvalue Decrement lvalue, returning the new value as the value of the expression. (This expression is like ‘++lvalue’, but instead of adding, it subtracts.)
  • lvalue-- Decrement lvalue, returning the old value of lvalue as the value of the expression. (This expression is like ‘lvalue++’, but instead of adding, it subtracts.)

Conclusion

That’s all for today. If you are interested in the MIT course you can check out the video lecture I’m currently going through. The lecture is helpful but isn’t sufficient by itself. Anyways, until next time PEACE!

YouTube player