facebook youtube pinterest twitter reddit whatsapp instagram

Bash Programming

OMG! Finally, I am getting into scripting ;) I have always wanted to know some basic scripting to automate my system admin workload, and finally, I have decided to dive into that realm, enjoy my bash tutorials.
  • How To Find Out Who Is Logged In On a GNU/Linux Server

    How To Find Out Who Is Logged In On a GNU/Linux Server

    Sometimes you just want to find out the bugged logged into your system ;), It might be your co-worker or friends. To find out who is logged in including the time they logged in, you can use the whoc

  • Getting Started With Bash (Introduction)

    Getting Started With Bash (Introduction)

    This is my first post on bash scripting, and I decided to delve into bash scripting because I am tired of doing repetitive tasks manually. So, if you ask me why use bash? My answer would be, if you w

  • Properly Naming a Bash Scripts

    Properly Naming a Bash Scripts

    Last week, I wrote a basic intro on bash shell scripting in this guide, we would take a look at how to name a script properly. Let's get this straight, we mostly do name things abruptly in the real

  • Using echo with Options in a Shell (With Examples)

    Using echo with Options in a Shell (With Examples)

    The echo command is one of the most used shell built-in command, and as you have probably guessed, it is used to print a line of text to standard output (the screen). It sends a copy of an input sign

  • Adding Comment To a Script

    Adding Comment To a Script

    In shell scripting, a comment is a readable explanation in a script that is ignored by the interpreter, you can either add a comment about what the script does or you can write a comment about what a

  • Using read in a Bash Script

    Using read in a Bash Script

    We previously looked at using echo with options in a shell, in this guide we would combine it with read command to prompt for user input. Create and open up a new text file: nano $HOME/bin/hw3.sh Ad

  • Create Multiple Files at Once Using Brace Expansion in BASH

    Create Multiple Files at Once Using Brace Expansion in BASH

    Chances are you've come across expansions in BASH, whenever you are going back to the user home directory, we use the cd command alongside a tilde character (~), e.g: cd ~ This would take you back to

  • Pipes and Redirection in Bash

    Pipes and Redirection in Bash

    Piping is the process where the result of one command is sent or pipe (redirect) into another command. A good example of this is piping the output of ls command into wc (count) for counting the numbe

  • Working With Variables In Bash

    Working With Variables In Bash

    A variable is a value that can change depending on conditions or data passed to the program. To work with the variable in bash, here are what you need to know: A variable name cannot start with a nu

  • Limiting The Number of Entered Characters In read prompt

    Limiting The Number of Entered Characters In read prompt

    We previously looked at the way we could utilize the read prompts in bash, here is the script we wrote in out last guide: #!/bin/bash read -p "What is Your Name? " name echo "Your Name is $name" exit

  • Suppressing Sensitive Entered Text/String In Bash

    Suppressing Sensitive Entered Text/String In Bash

    So far in our examples or scripts, we have written in the previous guides, we have no way of controlling what is visible to user, which is fine if we have no sensitive data such as passwords. As soon

  • Sourcing With Bash

    Sourcing With Bash

    Generally, to run a bash program or script you need to add a permission bit, which makes the program or script executable and you then run it whenever you like, the thing is when execution starts, a

  • Local Variable, Typset and The Declare Command In Bash

    Local Variable, Typset and The Declare Command In Bash

    Local variables are private inside of a function and the most important thing about a local variable is that when it is changed in a function, it doesn't affect the variable outside of a function. If

  • read prompts in bash script

    read prompts in bash script

    We've previously taken a quick look at the builtin read command, where we use the built-in read to populate the $REPLY variable, which holds the value of read when a variable is not supplied to read

  • Simple Conditional Execution With (Command Lists)

    Simple Conditional Execution With (Command Lists)

    We've previously explored a little of a command list in our Getting Started with Bash Guide, where we check if a directory already existed in our user home directory, if it already exists, output “

  • Check If Variable Is Not Empty [isset] (Bash)

    Check If Variable Is Not Empty [isset] (Bash)

    In the getting started with bash guide, we took a sneak peek in customizing script with argument, the issue with the example is that we aren't checking if the variable is set or not before returning

  • Test Shell Builtin Command

    Test Shell Builtin Command

    The test command can be a shell builtin or file executable (if you specify the full path to the file) that is used for file comparison, it returns a status of 0 (true) or 1 (false) depending on the

  • Creating Conditional Statements Using if And Else (Bash)

    Creating Conditional Statements Using if And Else (Bash)

    We have recently explored command-line list, we also dived into the test shell builtin command, which can not only be used to check file types but can also be used to compare values. The issue with u

  • Script to Replace/substitute Multi Occurrences of A String in Files

    Script to Replace/substitute Multi Occurrences of A String in Files

    There are a couple of ways you can replace a string in a file, and an example is using the mv command, but what if you want to replace multiple strings at once, then you might consider creating a loo

  • Iterating With Loops (Bash)

    Iterating With Loops (Bash)

    Imagine having to edit 10,000 lines of text within a CSV file, this would be a shit load of work if done manually, which is where looping comes in. When a task or a series of tasks needs to be repeat