Здравствуйте. В процессе возни с бэкендом для альтераторового модуля наткнулся на "было бы неплохо здесь взять имя переменной из другой переменной". Попробовал (смутно помня, что когда-то с eval и \ такое делал); спросил коллег; наконец, погуглил:
bash variable "name from variable" => http://www.linuxquestions.org/questions/programming-9/bash-how-to-get-variable-name-from-variable-274718/ A="abcd dcba" B=A C=${!B} echo $C A="abcd dcba" B=A C='eval "echo \$$B"' eval "$C" или как вариант -- name=a; a=1; eval echo \$$name name=a; a=1; eval c=\$$name Первый вариант (с ${!B}) -- явно sh/bash specific, по крайней мере мой zsh так не смог; eval \$$name работает в sh/bash/zsh/ash. Но этот самый вариант, судя по man bash, несколько более навёрнутый и может пригодиться для более обширных задач: ${!prefix*} [EMAIL PROTECTED] Expands to the names of variables whose names begin with prefix, separated by the first character of the IFS special variable. [EMAIL PROTECTED] ${!name[*]} If name is an array variable, expands to the list of array indices (keys) assigned in name. If name is not an array, expands to 0 if name is set and null otherwise. When @ is used and the expansion appears within double quotes, each key expands to a separate word. Может, кому-нибудь пригодится :) -- ---- WBR, Michael Shigorin <[EMAIL PROTECTED]> ------ Linux.Kiev http://www.linux.kiev.ua/ _______________________________________________ smoke-room mailing list [email protected] https://lists.altlinux.org/mailman/listinfo/smoke-room
