Nono.MA

APRIL 18, 2022

Here's how to prompt for user input from a Makefile.

USERNAME ?= $(shell bash -c 'read -p "Username: " username; echo $$username')
PASSWORD ?= $(shell bash -c 'read -s -p "Password: " pwd; echo $$pwd')

talk:
	@clear
	@echo Username › $(USERNAME)
	@echo Password › $(PASSWORD)

You can then execute make talk.

You'll be prompted for a username and password. The variables will get stored as USERNAME and PASSWORD, respectively, and the talk command will print them out to the console.

Note that the password read prompt specifies the -p flag, which hides the characters as you type and stores its value in the PASSWORD variable.

JUNE 10, 2019

#!/bin/bash

#!make
include .env
export $(shell sed 's/=.*//' .env)

Want to see older publications? Visit the archive.

Listen to Getting Simple .