blob: 940b0900c8c9aeed259d8d0258983191d3954f36 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# Requires Bash >= 4.0 for read -i and ${!name}
((BASH_VERSINFO[0] >= 4)) || return
# Edit named variables' values
vared() {
local opt prompt
local OPTERR OPTIND OPTARG
while getopts 'p:' opt ; do
case $opt in
p)
prompt=$OPTARG
;;
\?)
printf 'bash: %s: -%s: invalid option\n'
"$FUNCNAME" "$opt" >&2
return 2
;;
esac
done
shift "$((OPTIND-1))"
if ! (($#)) ; then
printf 'bash: %s: No variable names given\n' \
"$FUNCNAME" >&2
return 2
fi
local name
for name ; do
IFS= read -e -i "${!name}" -p "${prompt:-$name=}" -r -- "$name"
done
}
complete -A variable vared
|