Append to Bash Array

Watch out! This tutorial is over 3 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

The array data type is used in bash to store multiple data. The new data can be inserted at the end of an array variable in various ways. Bash has no built-in function like other programming languages to append new data in bash array. How you can insert single and multiple data at the end of the array in bash is shown in this tutorial.

Continue reading

How to clear bash history completely?

Watch out! This tutorial is over 4 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

Sometimes you don’t want to leave commands in the Bash history (accessed with UP key) of your Linux server available to other users, because it may contain some sensitive data like passwords.

This tutorial may help you to control your Bash history file, which is where these commands are actually stored.

Continue reading

Variables in Bash

Watch out! This tutorial is over 5 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

For those of you that have dabbled in programming before, you’ll be quite familiar with variables. For those of you that haven’t, think of a variable as a temporary store for a simple piece of information. These variables can be very useful for allowing us to manage and control the actions of our Bash Scripts. Today we’ll go through a variety of different ways that variables have their data set and ways we can then use them.

Continue reading

Managing WordPress with WP-CLI

Watch out! This tutorial is over 6 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

WP-CLI is a command line interface which allows the users to manage their WordPress web sites from the command prompt. Upgrades can be performed, backups can be generated, new posts can be published and most of the regular admin actions can be performed with a set of commands.

Continue reading

Hello World in Bash

Watch out! This tutorial is over 8 years old. Please keep this in mind as some code snippets provided may no longer work or need modification to work on current systems.

This is how you would display “Hello World” in Bash.

Create a text file called hello_world.sh containing the following code:

#!/bin/bash
# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING

Navigate to a directory where your hello_world.sh is located and make the file executable:

$ chmod +x hello_world.sh

Now you are ready to execute your first bash script:

./hello_world.sh