The Bash shell is the most popular shell on Linux systems, and to use the shell efficiently, you need a little knowledge about Bash shell redirections. This is also an essential step in learning Bash scripting.

In this guide, we'll show how to append text or command output to a file on the Bash shell command line. This will include several examples so you can pick the right method in any scenario.

In this tutorial you will learn:
  • How to append text or command output to a file
  • How to append and view command output at the same time
  • How to append multiple lines of text to a file
Appending text to a file in Bash on Linux
Appending text to a file in Bash on Linux

Wordpress is probably the most used CMS in the world (it is estimated that almost 40% of all websites are built using the platform): it is very easy to install and use, and allows even non-developers to create website in few minutes. Wordpress has a very large plugin ecosystem; one of the most famous is Woocommerce, which allows us to turn a website into an online store in few steps. The plugin makes use of the Wordpress REST API infrastructure; in this tutorial we will see how to interact with the Woocommerce API using the Python programming language, showing how to list, create, update and delete products and categories.

In this tutorial you will learn:

  • How to generate Woocommerce REST API credentials and enable pretty permalinks
  • How to interact with the Woocommerce REST API using Python and the woocommerce package
  • How to get information about the existing Woocommerce categories, create, update and delete them
  • How to get information about the existing Woocommerce products
  • How to create simple and a variable products with variations
  • How to update and delete a product

How we express a number depends on whether we are a computer or a human. If we are human, we are likely to express numbers using our familiar 10-base decimal system. If we are a computer, we are likely, at our core, to express numbers as 2-base or binary.

So what is up with all the many ways of expressing numbers, and why do they exists? This article will go into some detail and hopefully by the end you’ll be counting octal on your fingers. Which works fine by the way, as long as you use only 8 fingers, after all… octal is 8-base.

In this tutorial you will learn:

  • How to do simple counting in up non-decimal systems like binary, hexadecimal and octal.
  • What the terms 2-base, 10-base etc. stand for and how to understand them more easily.
  • The connection between these various methods of expressing numbers

Bash is a great coding language, which allows you to do complex things like Big Data Manipulation, or simply create sever or desktop management scripts.

The entry level skill required to use the Bash language is quite low, and one-liner scripts (an often used jargon, which indicates multiple commands executed at the command line, forming a mini-script), as well as regular scripts, can grow in complexity (and how well written they are) as the Bash developer learns more.

Learning to use special variables in Bash is one part of this learning curve. Whereas originally the special variables may look cryptic: $$, $?, $*, $0, $1, etc., once you understand them and use them in your own scripts, things will soon become clearer and easier to remember.

In this tutorial you will learn:

  • How to use special variables in Bash
  • How to correctly quote variables, even special ones
  • Examples using special variables from the command line and scripts

On Linux and Unix-based operating systems, pipes are very useful since they are a simple way to achieve IPC (inter-process communication). When we connect two processes in a pipeline, the output of the first one is used as the input of the second one. To build a so called “anonymous” pipe, all we have to do is to use the | operator. Anonymous, or unnamed pipes last just as long as the processes they connect. There is, however, another type of pipe we can use: a FIFO, or named pipe. In this article we will see how named pipes work and in what they are different from the standard pipes.

In this tutorial you will learn:

  • What is a named pipe
  • How to create a named pipe
  • How to recognize a named pipe
  • How named pipes work
  • How to delete a named pipe

If you are just starting to explore the Bash coding language, you will soon find yourself wanting to create conditional statements. Conditional statements, in other words, define ‘if a condition is true or false, then do this or that, and if the opposite is true, do something else’. This is the most basic function of any conditional statement.

This article will introduce you to the five basic if statement clauses. being if, elif, else, then and fi. The first simply opens a if statement, the then introduces the what commands to execute if the statement condition was true section and the else introduces the what commands to execute if the statement condition was false section. Finally, the fi closes the statement. We also have the special elif on which we will see more in a minute. Let’s start with an easy example.

In this tutorial you will learn:

  • How to implement an if statement at the Bash command line
  • How such if statements can also be used inside a Bash scripts
  • Examples showing you the if, elif, else, then and fi clauses in Bash

As sever optimal use/maximization continues to grow, it becomes more and more important to manage processes well. One aspect of this is automatic process termination. When a process has gone rogue, and is consuming too much resources, it can be terminated automatically.

This is especially suited to servers which have a lot of temporary or disposable processes. It is also well suited for testing servers which are running many test trials and where such test trials prove to be unstable or cause the software under testing to behave erratically (for example by using too much memory)

In this tutorial you will learn:

  • How to manage processes in an automated fashion
  • Which resources you may want to monitor, and why
  • Example code showing how automatic process termination can work for memory hogging issues

If you have ever used Bash subshells ($(...)), you know how flexible subshells can be. It only takes a few characters to start a subshell to process anything required, inline to another statement. The number of possible use cases is virtually unlimited.

We can also use Bash subshells inside if statements, inline with the statement. Doing so gives the user and developer much additional flexibility when it comes to writing Bash if statements.

If you are not familiar yet (or would like to learn more about) Bash if statements, please see our Bash If Statements: If Elif Else Then Fi article.

In this tutorial you will learn:

  • How to incorporate Bash subshells inside if statements
  • Advanced methods to incorporate Bash subshells inline with other commands
  • Examples demonstrating the use of Bash subshells in if statements

In general, one may use the time Bash utility (see man time for more information) to run a program, and obtain runtime duration and system resource usage summaries. But how can one time particular sections of code, directly from within the Bash source code?

Using some easy variable assignments and calculations, it is possible to achieve accurate timing metrics for Bash script executions.

In this tutorial you will learn:

  • How to time Bash scripts using variable assignments and calculations
  • How to use overlapping timers to time specific sections of your scripts
  • Examples which exemplify how specific sections of code can be timed

In our automation scripts we often need to launch and monitor external programs to accomplish our desired tasks. When working with Python, we can use the subprocess module to perform said operations. This module is part of the programming language standard library. In this tutorial we will take a quick look at it, and we will learn the basics of its usage.

In this tutorial you will learn:

  • How to use the “run” function to spawn an external process
  • How to capture a process standard output and standard error
  • How to check the exist status of a process and raise an exception if it fails
  • How to execute a process into an intermediary shell
  • How to set a timeout for a process
  • How to use the Popen class directly to pipe two processes

CSV is the acronym of “Comma Separated Values”. A csv file is a just plain text document used to represent and exchange tabular data. Each row in a csv file represents an “entity”, and each column represents an attribute of it. Columns are usually separated by a comma but other characters can be used as field separator instead of it. In this tutorial we will see how to read and create csv files using Python and specifically the csv module, which is part of the language standard library.

In this tutorial you will learn:

  • How to read csv rows as a list of strings
  • How to read a csv as a list of dictionaries
  • How to create a csv using Python
  • How to create a csv starting from a list of dictionaries

grep is a versatile Linux utility, which can take a few years to master well. Even seasoned Linux engineers may make the mistake of assuming a given input text file will have a certain format. grep can also be used, directly in combination with if based searches to scan for the presence of a string within a given text file. Discover how to correctly grep for text independent of character sets, how to use the -q option to text for string presence, and more!

In this tutorial you will learn:

  • How to do correct character set-independent text searches with grep
  • How to use advanced grep statements from within scripts or terminal oneliner commands
  • How to test for string presence using the -q option to grep
  • Examples highlighting grep usage for these use cases

Whenever we work with textual strings, sooner or later the issue of case comes up. Does a word need to be fully uppercase, fully lowercase, with a capitalized letter at the start of the word or sentence, and so on.

An idiom is a natural language expression of a simple programming task. For example, in the sleep 10 command (which will pause the terminal one is working in for ten seconds), the word sleep is a natural language expression of what is a time based coding construct, developed in the Bash GNU coreutils software package.

There are a number of special variable-bound idioms (i.e. suffixes which can be added to a variable name, indicating what we would like to do with a given variable), which can be used in Bash to more easily do these types of conversions on the fly instead of having to use for example the Sed Stream Editor with a Regular Expression to do the same.

If you are interested in using regular expressions, have a look at our Bash Regexps For Beginners With Examples Advanced Bash Regex With Examples articles!

This makes working with variables that need case modification, or if statement testing a whole lot easier and provides great flexibility. Idioms can be added directly inside the if statements and do not need to employ a subshell with sed.

While the syntax looks slightly complex to start with, once you learn a little mental support trick to remember the right keys, you will be well on your way to use these idioms in your next script or Bash one-liner script at the command line!

In this tutorial you will learn:

  • How to use the ^, ^^, , and ,, Bash variable suffix idioms
  • How to use a regular expression [] range idiom in combination with these
  • How to use the ^ and , idioms directly from within if statements
  • Detailed examples exemplifying the use of ^, ^^, , and ,,

This tutorial will explain the Bash string concatenation by using examples. When it comes to bash scripting or programming in general, the concatenation refers to joining two or more string together to produce single unified output. Using Bash shell and bash scripting the string concatenation can be achieved in number for ways.

In this tutorial you will learn:
  • How to concatenate strings using echo command
  • How to concatenate strings in loop
  • How to concatenate string with command output

Decimal calculations are sometimes required in Bash. The standard calculation Bash programming idiom ($[]) is unable to provide a decimal output. Whilst we can trick it into calculating (but not generating) a decimal output by multiplying the numbers by for example a factor of 1000 and then doing an text based splitting, this is a ugly workaround and creates complex code. There is however a utility in Bash which can natively do decimal based calculations without any tricks or workarounds!

In this tutorial you will learn:

  • How to use bc to perform decimal calculations
  • How to make decimal based calculations at the Bash command line or from in your scripts
  • How to use variables to store the results produced by bc
  • How to use variables in further calculations
  • How to avoid Bash variable quoting errors

Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: