Created
July 10, 2018 16:54
-
-
Save mminer/c749ace6e22a12a01fbbb201449c9f73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Watches a file and prints when a specified variable value changes. | |
| # We assume the file is a list of key=value pairs separated by newlines. | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 FILE KEY" | |
| exit 1 | |
| fi | |
| file="$1" | |
| key="$2" | |
| read_value() { | |
| grep --only-match --perl-regexp "${key}=\K.*" "${file}" | |
| } | |
| value="$(read_value)" | |
| while true; do | |
| inotifywait --quiet --quiet "${file}" | |
| new_value=$(read_value) | |
| if [ "${new_value}" == "${value}" ]; then | |
| continue | |
| fi | |
| value="${new_value}" | |
| echo "${value}" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment