Recently I’ve attended a two-day workshop on the concept of “Shell Scripting” under the mentorship of Mr. Vimal Daga Sir..!!

Key Takeaways:

  • there are multiple ways to interact with an OS like CLI GUI and so on
  • Shell is the program that will provide us, users, an interface for interacting with the OS, the most mainstream Shell right now is the Bash shell
  • CLI or command-line interface is the type in which the interaction is done only in the form of text
  • Variables are the ones that we use to store data and these can only affect the current shell
  • Exit/Return code is the one that returns to a parent process via executable
  • Exit code is supposed to be 0 when success, and otherwise if any number ranging from 1–255
  • a script consists of a list of instructions whereas a command consists of a single instruction
  • Shebang or #1 is used at the top of an executable script for specifying the path for the program’s interpreter/compiler/shell
  • Understood the fact that we can pass positional parameters in a script when running it, but its first arg is stored in 1 and second in 2 by default
  • a live interpreter gives the output to a cmd instantly
  • Migration operations are the processes that transfer files from one system to another
  • Redirection is defined as a process of changing how commands can read input to where it sends the output
  • we use read to take user input, for eg: read -p “Prompt” variable_name.
  • while is another loop, but we mostly use it when we don’t know the number of loops to take place
  • we can omit a part of input using cut cmd
  • awk is a general-purpose scripting language for an advanced form of text processing
  • we can use watch cmd at regular interval for displaying the output of the cmd on the cli
  • if we wish to obtain the total number of false clients we can use:
    awk $9==404 { print $1 “ “ $7 }’ access_log | sort | uniq -c | sort -n
  • the tail cmd will display only the last 10 lines (by default) of one or more files or piped data
  • if we wish to filter out the data, month,year from the date output we use:
    date +%e/%b/%G
  • if we wish to run multiple shell cmds in one line we use either:
    1. && in this case cmds will run successfully one after the other
    2. ; the second cmd is always executed
    3. || if first fails, then the second cmd is run
  • we can use touch cmd to create multiple .txt files at once by:
    touch a{1,2,….12}.txt
    this will create text files named a1.txt, a2.txt, and so on till a12.txt
  • awk ‘{ print $<n> }’ is a file command that prints the nth field of every record.
  • NR stands for the no.of current records, this is used in :
    awk ‘{ print NR }’ input-file
  • we can also sort and count log lines using awk cmd :
    awk ‘{ print $1 }’ access_log | sort | uniq -c | sort -n -k1
    Func_name() {stmts/cmds/instructions} is the syntax for defining a function
  • we can search for specific patterns using awk as well
  • similarly, sed is a cmd used in text processing, it can perform a search, replace, and delete operations on strings in any given file or text.

I’d like to thank Vimal Daga Sir, Preeti Ma’am, and the whole LinuxWorld Informatics Pvt Ltd team for organizing such a great workshop.

Thank you for the time~!