Bash Operators & Shell Tricks: Level Up Your Scripting

Learn about logical operators and shell expansions, in the second article in this multi-part series on programming with Bash. Author’s note: The articles in this series first appeared at Opensource.com. The original articles consisted of two series and the rest were published as stand-alone articles. These have all been merged into a single series with updates and modifications for that purpose.

Source: Bash Operators & Shell Tricks: Level Up Your Scripting – OpenSource.net

A handy tip for entering long and/or complicated commands at the Linux command prompt (when using the bash shell) from a Mastodon user

Saw this tip on Mastodon from user Stephan (@durchaus@mastodon.social) and thought it worth passing along:

When you are about to write a long and complicated command in bash, then hit CTRL+x CTRL+e to enter an editor window in which you can write the command with your default editor. The command will be executed immediately after the file is saved and the editor is closed.

(Link to post)

I never knew you could do this. And it was only a year or two ago that I found about about CTRL+r which lets you do a text search for commands in your history (so you don’t need to keep pressing the up arrow). Then again I am not a big command line user, but when I do need to use it, tips like these can be quite helpful IF I can remember them when I need them!

Thanks to Stephan for sharing this tip!

How to Verify if a File or Directory Exists in Bash

Master Bash scripting with our guide on how to verify if a file or directory exists. Includes examples and best practices for reliable scripts.

Source: How to Verify if a File or Directory Exists in Bash – LinuxCapable
Similar article: Check if File or Directory Exists in Bash – It’s FOSS

Lesser Known Bash shortcuts

Did you know Bash has got macros, a multi-clipboard, an undo feature, and a word completion based on history?

Source: Lesser Known Bash shortcuts (GitHub)

How to check the bash shell script is being run by root user or not

Explains how to check if a bash shell script is being run or executed by the root user account under Linux, macOS, Unix and BSD.

Source: How to check the bash shell script is being run by root user or not – nixCraft

5 Modern Bash Scripting Techniques That Only A Few Programmers Know

The following concepts modernize your automation scripts with some lesser-known modern Bash scripting techniques.

Source: 5 Modern Bash Scripting Techniques That Only A Few Programmers Know | Level Up Coding

Use Date Command In Bash Scripting In Linux

This guide explains how to use date command in Bash scripting and how to work with date and time in shell scripts in Linux.

Source: Use Date Command In Bash Scripting In Linux – OSTechNix

Boost Up Productivity in Bash – Tips and Tricks

When spending most of your day around bash shell, it is not uncommon to waste time typing the same commands over and over again. This is pretty close to the definition of insanity.

Luckily, bash gives us several ways to avoid repetition and increase productivity.

Today, we will explore the tools we can leverage to optimize what I love to call “shell time”.

Source: Boost Up Productivity in Bash – Tips and Tricks | Linux Journal

Minimal safe Bash script template

Minimal Bash script template that will make your scripts safer, consistent with standards, and provide a way to parse and validate parameters.

Source: Minimal safe Bash script template | Better Dev

Writing Safe Shell Scripts

Writing shell scripts leaves a lot of room to make mistakes, in ways that will cause your scripts to break on certain input, or (if some input is untrusted) open up security vulnerabilities. Here are some tips on how to make your shell scripts safer.

Source: Writing Safe Shell Scripts (MIT Student Information Processing Board)