Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created July 17, 2019 10:50
Show Gist options
  • Select an option

  • Save mamemomonga/7d39c8713b86866fd2be252e1679f076 to your computer and use it in GitHub Desktop.

Select an option

Save mamemomonga/7d39c8713b86866fd2be252e1679f076 to your computer and use it in GitHub Desktop.
連番のシェル変数の取得
#!/bin/bash
set -eu
VALUE_1_NAME=aaa
VALUE_2_NAME=bbb
VALUE_3_NAME=ccc
showvalues() {
local v
for i in {1..10}; do
v=$( eval 'echo "${VALUE_'$i'_NAME:-}"' )
if [ -n "$v" ]; then
echo "$i [$v]"
fi
done
}
showvalues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment