Category: Bash

  • Conditionals

    Bash Conditionals In the last section, we covered some of the most popular conditional expressions. We can now use them with standard conditional statements like if, if-else and switch case statements. If statement The format of an if statement in Bash is as follows: if [[ some_test ]] then <commands> fi Here is a quick…

  • Conditional

    Bash Conditional Expressions In computer science, conditional statements, conditional expressions, and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false. In Bash, conditional expressions are used by the [[ compound command and the [built-in commands to test file…

  • Arrays

    Bash Arrays If you have ever done any programming, you are probably already familiar with arrays. But just in case you are not a developer, the main thing that you need to know is that unlike variables, arrays can hold several values under one name. You can initialize an array by assigning values devided by…

  • Arguments

    Bash Arguments You can pass arguments to your shell script when you execute it. To pass an argument, you just need to write it right after the name of your script. For example: ./devdojo.com your_argument In the script, we can then use $1 in order to reference the first argument that we specified. If we…

  • Comments

    Bash Comments As with any other programming language, you can add comments to your script. Comments are used to leave yourself notes through your code. To do that in Bash, you need to add the # symbol at the beginning of the line. Comments will never be rendered on the screen. Here is an example…

  • Input

    Bash User Input With the previous script, we defined a variable, and we output the value of the variable on the screen with the echo $name. Now let’s go ahead and ask the user for input instead. To do that again, open the file with your favorite text editor and update the script as follows:…

  • Variables

    Bash Variables As in any other programming language, you can use variables in Bash Scripting as well. However, there are no data types, and a variable in Bash can contain numbers as well as characters. To assign a value to a variable, all you need to do is use the = sign: name=”DevDojo” {notice} as…

  • Hello

    Bash Hello World Once we have our devdojo.sh file created and we’ve specified the bash shebang on the very first line, we are ready to create our first Hello World bash script. To do that, open the devdojo.sh file again and add the following after the #!/bin/bash line: #!/bin/bash echo “Hello World!” Save the file…

  • Creating

    Creating a Bash Script Let’s start by creating a new file with a .sh extension. As an example, we could create a file called devdojo.sh. To create that file, you can use the touch command: touch devdojo.sh Or you can use your text editor instead: nano devdojo.sh In order to execute/run a bash script file…

  • Intro

    Introduction to Bash In this bash crash course, you will learn the Bash basics so you could start writing your own Bash scripts and automate your daily tasks. Bash is a Unix shell and command language. It is widely available on various operating systems, and it is also the default command interpreter on most Linux…