diff options
-rw-r--r-- | bash/bashrc.d/vared.bash | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/bash/bashrc.d/vared.bash b/bash/bashrc.d/vared.bash new file mode 100644 index 00000000..a2066b4c --- /dev/null +++ b/bash/bashrc.d/vared.bash @@ -0,0 +1,19 @@ +# Requires Bash >= 4.0 for read -i and ${!name} +if ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} < 4)) ; then + return +fi + +# Edit named variables' values +vared() { + if ! (($#)) ; then + printf 'bash: %s: No variable names given\n' \ + "$FUNCNAME" >&2 + return 2 + fi + local name + for name in "$@" ; do + IFS= read -e -i "${!name}" -p "$name"= -r "$name" + done +} +complete -A variable vared + |