It turns out that the problem was that Makefiles didn’t use Dash / Bash-style quotes, and the built-in Dash read needed a variable name, unlike Bash. Receiving Code:
install-crontab-delicious: $(DELICIOUS_TARGET_PATH) @while [ -z "$$DELICIOUS_USER" ]; do \ read -r -p "Delicious user name: " DELICIOUS_USER;\ done && \ while [ -z "$$DELICIOUS_PASSWORD" ]; do \ read -r -p "Delicious password: " DELICIOUS_PASSWORD; \ done && \ while [ -z "$$DELICIOUS_PATH" ]; do \ read -r -p "Delicious backup path: " DELICIOUS_PATH; \ done && \ ( \ CRONTAB_NOHEADER=Y crontab -l || true; \ printf '%s' \ '@midnight ' \ '"$(DELICIOUS_TARGET_PATH)" ' \ "\"$$DELICIOUS_USER\" " \ "\"$$DELICIOUS_PASSWORD\" " \ "\"$$DELICIOUS_PATH\""; \ printf '\n') | crontab -
Result:
$ crontab -r; make install-crontab-delicious && crontab -l Delicious user name: a\bc\d Delicious password: efg Delicious backup path: h\ i no crontab for <user> @midnight "/usr/local/bin/export_Delicious" "a\bc\d" "efg" "h\ i" $ DELICIOUS_PASSWORD=foo make install-crontab-delicious && crontab -l Delicious user name: bar Delicious backup path: baz @midnight "/usr/local/bin/export_Delicious" "a\bc\d" "efg" "h\ i" @midnight "/usr/local/bin/export_Delicious" "bar" "foo" "baz"
This code:
- treats all input characters as literals, so it works with spaces and backslashes,
- avoids problems if the user presses Enter without writing anything,
- uses environment variables if they exist, and
- whether crontab works empty or not.
source share