Cancel

Shebang Line in Bash

#! shebang or shebang line is used to tell the operating system which interpreter to use to parse the rest of the file. Lets create your first hello world script. #!/bin/bash echo "Hello World" ...

Non-Positional/Positional arguments in Bash

Positional arguments are parameters that we can supply to our bash script while executing. # don't forget to set execute permission. cat <<EOF > my_script.sh echo "Hi, \$1 \$2" EOF # fir...

Loops in Bash

Loops are one of the fundamental concepts of programming languages. Loops are handy when you want to run a series of commands over and over again until a certain condition is reached. I am not gon...

Input, Output, and Error Redirection in Bash

Input, Output, and Error redirection is the most important topic to cover in Bash Scripting. Standard Output, aka stdout, whose symbolic value is > or >>. # over write data every time yo...

Input from User in Bash

Read command takes the input from a user and saves it onto a variable, so you can use it later on during your script. Ask a user to press Y or N to execute. read is a command to ask user to gi...

Heredoc in Bash

You can run any program within a shell script without user action by supplying the required input for the interactive program. EOF operator stands for the end of the file. This means that wherever...

Functions in Bash

The function is essentially a set of commands that can be called numerous times. The purpose of a function is to help you to make your bash scripts more readable and to avoid writing the same code ...

File Importing in bash

You can import a file in bash using the source command. Create few variables in vars file, so you can use these variables later on inside the different files. first_name="Yafiz" last_name="Abraha...

Fatal, Warning, Success, and Info color codes in Bash

Make your bash script messages colorful. I am going to use the xterm-256 color code because it is supported by pretty much all terminals. Foreground Formula Code: 38 Background Formula Code: ...

Execute Multiple Commands at Once in Bash

You can execute multiple commands at once, which helps you to reduce your stress level. Single line commands can be separated by semicolon after each command. echo "run this first"; echo "run thi...