From 699ab2911ca05d23200e6355dc51f9d2b3852146 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 28 Mar 2016 15:09:23 +1300 Subject: Add readv function --- README.markdown | 1 + bash/bashrc.d/readv.bash | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 bash/bashrc.d/readv.bash diff --git a/README.markdown b/README.markdown index 9a617c59..d6c61463 100644 --- a/README.markdown +++ b/README.markdown @@ -189,6 +189,7 @@ There are a few other little tricks in `bash/bashrc.d`, including: * `path` — Manage the contents of `PATH` conveniently * `paz` — Print given arguments separated by NULL chars * `pd` — Change to the argument’s parent directory +* `readv` — Print names and values from `read` calls to `stderr` * `readz` — Alias for `read -d '' -r` * `scr` — Create a temporary directory and change into it * `sd` — Switch to a sibling directory diff --git a/bash/bashrc.d/readv.bash b/bash/bashrc.d/readv.bash new file mode 100644 index 00000000..5013dd89 --- /dev/null +++ b/bash/bashrc.d/readv.bash @@ -0,0 +1,26 @@ +readv() { + local arg + local -a opts names + for arg ; do + case $arg in + --) + shift + break + ;; + -*) + shift + opts[${#opts[@]}]=$arg + ;; + *) + break + ;; + esac + done + names=("$@") + builtin read "${opts[@]}" "${names[@]}" || return + for name in "${names[@]}" ; do + printf >&2 '%s: %s = %s\n' \ + "$FUNCNAME" "$name" "${!name}" + done +} + -- cgit v1.2.3