Advanced Linux Subshells With Examples

Advanced Linux Subshells With Examples

If you read our previous linux subshells for beginners with examples article, or are experienced with subshells already, you know that subshells are a powerful way to manipulate Bash commands inline, and in a context sensitive manner.

In this tutorial you will learn:

  • How to create more advanced subshell commands
  • Where you can employ more advanced subshells in your own code
  • Examples of more advanced subshell commands

Read more

Linux Complex Bash One-Liner Examples

Linux Complex Bash One-Liner Examples

Bash one-liners can reduce workload, automate something quickly and put the power of ultimate system control in your hands. Over time, you will likely learn to write more complex one-liners and some of the things you end up writing as a seasoned professional will be nearly in-parsible by a beginner. That said, the Bash command and development language is highly structured – and relatively easy to understand – once you know about the in and outs. It really is like becoming proficient in a foreign language.

In this tutorial you will learn:

  • How to write more advanced Bash one-liner commands and scripts
  • Understand how to combine various commands into one-liner scripts
  • Understand how exit codes from one command can affect other commands when using && and ||
  • Understand how input from a command can be modified and then be used by the next command
  • Usage and real-life like examples of more advanced Bash one-liners

Read more

Generating Random Numbers In Bash With Examples

Generating Random Numbers In Bash With Examples

When coding Bash scripts – especially when developing scripts for functionality testing – we sometimes need to generate a random number or random input. These numbers may also need to be within a specific range. This article will teach you how to perform random number generation in Bash.

In this tutorial you will learn:

  • How to generate random numbers in Bash
  • How to generate random numbers is a specific range
  • Examples demonstrating random number generation in Bash

Read more

Multi-threaded xargs with examples

Multi-threaded xargs with examples

If you are new to xargs, or do not know what xargs is yet, please read our xargs for beginners with examples first. If you are already somewhat used to xargs, and can write basic xargs command line statements without looking at the manual, then this article will help you to become more advanced with xargs on the command line, especially by making it multi-threaded.

In this tutorial you will learn:

  • How to use xargs -P (multi-threaded mode) from the command line in Bash
  • Advanced usage examples using multi-threaded xargs from the command line in Bash
  • A deeper understanding of how to apply xargs multi-threaded to your existing Bash code

Read more

Comparing strings in Bash

Compare string in BASH

The need to compare strings in a Bash script is relatively common and can be used to check for certain conditions before proceeding on to the next part of a script. A string can be any sequence of characters. To test if two strings are the same, both strings must contain the exact same characters and in the same order. It could be a word or a whole sentence. For example, string one is equal to string one but is not equal to string two. Get the idea?

In this guide, we’ll show you how to compare strings in the Bash shell on a Linux system. We’ll show this in the context of a simple if/else Bash script so you can see how testing for this condition would work when developing scripts, but we’ll also show how this same comparison can be done in the command line terminal.

In this tutorial you will learn:

  • How to compare strings in Bash
  • Example if/else Bash scripts that compare strings

Read more

Linux Subshells for Beginners With Examples

Linux Subshells for Beginners With Examples

Making use of subshells in Bash provides you with an ability to generate context sensitive information from right within your Bash command. For example, if you want to modify a text string right inside an echo statement, then this can be done easily with subshells.

In this tutorial you will learn:

  • How to use employ the use of subshells in Bash
  • How to use subshells to obtain context sensitive information
  • Basic Bash subshell usage examples

Read more

How to propagate a signal to child processes from a Bash script

How to propagate a signal to child processes from a Bash script

Suppose we write a script which spawns one or more long running processes; if said script receives a signal such as SIGINT or SIGTERM, we probably want its children to be terminated too (normally when the parent dies, the children survives). We may also want to perform some cleanup tasks before the script itself exits. To be able to reach our goal, we must first learn about process groups and how to execute a process in background.

In this tutorial you will learn:

  • What is a process group
  • The difference between foreground and background processes
  • How to execute a program in background
  • How to use the shell wait built in to wait for a process executed in background
  • How to terminate child processes when the parent receives a signal

Read more

xargs for beginners with examples

xargs for beginners with examples

Using xargs, described in the Linux xargs manual as a tool which builds and execute command lines from standard input, once can exert a significant amount of additional power over any other command executed on the Bash command line. Basically, xargs will take the output from any other tool, and use that as it’s own input for further processing and action (hence the reference to executing command lines in the manual). If this is your first few weeks or months with xargs, or you are only just starting, this is the best place for you to get into xargs.

In this tutorial you will learn:

  • How to use xargs from the command line in Bash
  • How xargs works, what it does, and how to use it well
  • Basic usage examples using xargs from the command line in Bash

Read more

Random Entropy in Bash

Random Entropy in Bash

When using random numbers in Bash, the question of random entropy will sooner or later come up. This article will help you understand what entropy is, how it can be modified and optimized in Bash, and how it will affect random number generation.

In this tutorial you will learn:

  • How to generate random entropy in Bash
  • How to pre-seed the random number generator in Bash
  • Examples demonstrating random entropy generation in Bash

Read more

Bash regexps for beginners with examples

Bash regexps for beginners with examples

Using regular expressions in Bash provides you with plenty of power to parse nearly every conceivable text string (or even full documents), and transform them into nearly any output desirable. If you regularly use Bash, or if you regularly work with lists, textual strings, or documents in Linux, you will find that many jobs can be simplified by learning how to use regular expressions in Bash. Continue reading to learn basic Bash regular expression skills! If you are already familiar with basic regular expressions in Bash or another coding language, see our more advanced bash regular expressions. If not, continue reading to learn basic Bash regular expression skills!

In this tutorial you will learn:

  • How to use regular expressions on the command line in Bash
  • How regular expressions can parse and transform any text string and/or document
  • Basic usage examples of regular expressions in Bash

Read more

Advanced Bash regex with examples

Advanced Bash regex with examples

Using the power of regular expressions, one can parse and transform textual based documents and strings. This article is for advanced users, who are already familiar with basic regular expressions in Bash. For an introduction to Bash regular expressions, see our Bash regular expressions for beginners with examples article instead. Another article which you may find interesting is Regular Expressions in Python.

Ready to get started? Dive in and learn to use regexps like a pro!

In this tutorial you will learn:

  • How to avoid small operating system differences from affecting your regular expressions
  • How to avoid using too-generic regular expression search patters like .*
  • How to employ, or not employ, extended regular expression syntax
  • Advanced usage examples of complex regular expressions in Bash

Read more