Skip to main content

17 posts tagged with "bash"

View All Tags

Batch edit of environment file

4 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Batch edit of environment file

When deploying a project on servers, we need to pay particular attention to the .env file. This file is crucial and will determine whether our application works properly (or crashes).

The normal way of doing things is to run a git clone command to get the latest version of the application from a repository (branch test for a test server, dev for an acceptance server, main for a production server).

Once cloned, the next command will be to create the .env file and it's done using cp .env.example .env.

And that's where the obligation to be meticulous begins.

Search and replace (or add) using sed

3 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Search and replace (or add) using sed

Today, I was facing (once more) with the following need: I need to update a setting in a text file but if the variable is not yet present, I need to add it.

So, in short, I need to make a search and replace or insert new line.

Using sed it's quite easy to automate the search & replace but how to append?

Bash - ASCII art

2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Bash - ASCII art

I write a lot of Bash scripts, and I like to have a similar approach for each one. One of the things I always do is to include a good old-fashioned ASCII Art banner, perhaps for the geek factor, but mostly to make a bigger visual impact.

I use https://patorjk.com/software/taag to create my banners, so let's take a closer look.

Sample ASCII art

Bash - Loading environment variables from a file

2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Bash - Loading environment variables from a file

Imagine you've a .env file like and you wish to process that file in a Bash script.

DOCKER_GIT_USEREMAIL="christophe@me.com"
DOCKER_GIT_FULLNAME="Christophe Avonture"
DOCKER_GIT_USERNAME="Me and myself"

Using a configuration file will enable you to externalize the management of your constants, as well as reuse variables from another application, such as a site developed in Laravel.

Let's take a look at how to do this as correctly as possible.

The jq utility for Linux

3 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

The jq utility for Linux

jq is a powerful utility for Linux allowing manipulating JSON data from the command line and can be integrated into shell scripts.

Using jq you can beautify JSON output but also filter it like f.i. showing only a given node.

The xmlstarlet utility for Linux

3 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

The xmlstarlet utility for Linux

xmlstarlet is a powerful utility for Linux allowing manipulating XML data from the command line and can be integrated into shell scripts.

Using xmlstarlet you can beautify XML output but also filter it like f.i. showing only a given node.

Get health information from your running containers

2 min read
Christophe
Markdown, WSL and Docker lover ~ PHP developer ~ Insatiable curious.

Get health information from your running containers

When you've a few runnings containers on your machine, you can quickly retrieve the health information using docker ps and his State.Health response.

In this article, we'll look at how to create a bash script that can be used as a basis for other needs.