Bourne-Again SHell


made-with-bash Ubuntu 22.10 Become a sponsor to JV-conseil Follow JV conseil on StackOverflow Follow JVconseil on Twitter Follow JVconseil on Mastodon Follow JV conseil on GitHub

The only way to really learn scripting is to write scripts – Mendel Cooper

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… The simplest step is to avoid using shell at all – MIT Student Information Processing Board

Table of Content

Extract a substring from a string

With grep -Eo and a regex pattern

grep -Eo "http[^ ']+" <<EOF
curl ''
-H 'Accept-Language: en-US,en;q=0.5'
-H 'Accept-Encoding: gzip, deflate, br'
-H 'Authorization: Bearer ****'
-H 'Content-Type: application/json; charset=utf-8'
-H 'Cookie: refreshToken=cf6220bd%2D650c%2D4a48%2D9836%2D58ea9ecb7567'
-H 'Sec-Fetch-Dest: empty'
-H 'Sec-Fetch-Mode: cors'
-H 'Sec-Fetch-Site: same-origin'
-H 'Pragma: no-cache'
-H 'Cache-Control: no-cache'

will output

src 👉

Extract a value from a file

Example of a pyproject.toml file

name = "docs"
version = "0.1.0"
description = "Collection of Cheatsheets 🗒️ PostgreSQL 🐘, Git..."
repository = ""

With grep and sed

grep -Eo "^repository.+$" pyproject.toml | sed -E 's/^repository = "(.+)"$/\1/'

will output

Read a JSON stream

With jq

curl '' \
-H 'Accept-Language: en-US,en;q=0.5' \
-H 'Accept-Encoding: gzip, deflate, br' -H 'Authorization: Bearer *****' \
-H 'Content-Type: application/json; charset=utf-8' \
--compressed | jq '.items[].specification.domain' >~/Downloads/example.json

will output


src 👉 jq/manual

Tools for Shell Script Development ⚙️

Integrates ShellCheck into VS Code, a linter for Shell scripts
A formatter for shell scripts implementing shfmt parser, formatter, and interpreter
See Google Shell Style Guide

General 📚

Features 🔎

Coding Guidelines, Style, Linter ✍️


If this project helps you, you can offer me a cup of coffee ☕️ :-)

Become a sponsor to JV-conseil