Expanding a globed variable name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expanding a globed variable name
# 1  
Old 05-16-2015
Expanding a globed variable name

Heyas

I'm trying to give some information on used variables.
While the first two work fine, the ones starting with a glob (is that the proper term?) fail.

Code:
echo ${!TUI_*} ${!RET_*} ${!*_CLI} ${!*\_GUI}
bash: ${!*_CLI}: bad substitution

Same with @ or have them escaped.

I found no indication for using suffix Smilie
Code:
       ${!prefix*}
       ${!prefix@}
              Names  matching  prefix.  Expands to the names of variables whose names begin with prefix, separated
              by the first character of the IFS special variable.  When @ is used and the expansion appears within
              double quotes, each variable name expands to a separate word.

       ${!name[@]}
       ${!name[*]}
              List  of  array  keys.   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.

Any ideas/advice please?

---------- Post updated at 16:02 ---------- Previous update was at 15:43 ----------

Nevermind, i'm reading out the files providing the variables to read the variable names, and evalute them to show what currently is in memory.
Code:
tui-printf -T "Variables provided by sourcing TUI (User specific)"
			
list=""
list+=" $(tui-conf-get -l $TUI_FILE_CONF_USER)"
list+=" $(tui-conf-get -l $TUI_FILE_CONF_APPS)"
list+=" $(tui-conf-get -l $TUI_FILE_CONF_SETTINGS)"

for foundVar in $list 
do	tui-printf -E \
		"$foundVar" \
		"$(tmp=\$$foundVar ; printf '%s' $(eval echo $tmp))"
done

Replace tui-printf -E by something like printf '%s\t\t%s\n'

/solved

EDIT:
Outputs like:
Code:
tui info
<....>
:: Variables provided by sourcing TUI (User specific) ::
:: USER_NAME                                      sea ::
:: USER_EMAIL              seaATlocalhost.localdomain ::
:: USER_HOMEPAGE                                      ::
:: DEFAULT_LICENSE       GNUGeneralPublicLicense(GPL) ::
:: TUI_THEME                                 dot-blue ::
:: EDITOR_GUI                               notepadqq ::
:: EDITOR_CLI                                    nano ::
:: BROWSER_CLI                                   lynx ::
:: BROWSER_GUI                                firefox ::
:: TERMINAL                                    termit ::
:: TAR_EXT                                     tar.gz ::
:: DD_BS                                           4M ::
:: CURLWGET                                      wget ::
:: TAR_EXT                                     tar.gz ::
:: DD_BS                                           4M ::
:: USER_SHELL                                    bash ::


Last edited by sea; 05-16-2015 at 11:12 AM..
# 2  
Old 05-16-2015
How about (bashism?)
Code:
A_CLI=öjkb3brljv
B_CLI=12124

set | grep "^.*_CLI"
A_CLI=öjkb3brljv
B_CLI=12124

This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-16-2015
Figured my method is simpler (for the current task), as i also (have to) provide some variable names that cannot follow a regular naming scheme.

Also, this way i dont have to rewrite the variable names (here) if i should change them (in the conf files).

Hope i recall this option at next occourence, thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sed variable not expanding

I have also some difficulty calling sed to change a word in a file. sed -i 's/docTitl/Outline ${docTitl}/g' $ofln Moved to new thread, since it is a different question (3 Replies)
Discussion started by: Danette
3 Replies

2. Shell Programming and Scripting

Longlist files without expanding

Hi, I want to long list files within a file.tar.Z/file.tar.gz file. I tried these: I'm working on HP UX 11iV3 OS tar -tvzf file.tar.gz -->not working as 'z' is not supported gunzip -c file.tar.gz | tar tvf - -->does this unizip the tar file? i don't want it to be unzipped. ... (1 Reply)
Discussion started by: sam_bd
1 Replies

3. Shell Programming and Scripting

Quick question on expanding variable

s=`awk '{ print $0}' /Applications/Relink.app/z_cloudline.txt` sed -n '"$s"' /var/mobile/Library/iFile/Bookmarks.plist > /var/mobile/originalip.txt What is the problem with that code ? With variable it only outputs: sed: -e expression #1, char 1: unknown command: `"' If I use the... (3 Replies)
Discussion started by: pasc
3 Replies

4. Solaris

expanding RAM

our sparc server has only 1Gb RAM. Since RAM is not very expensive anymore, it seems like a good idea to upgrade it. will it make server (and database on it) faster? I hope it would less 'abuse' hard drive.. (6 Replies)
Discussion started by: orange47
6 Replies

5. Solaris

Variable not expanding during Solaris pkgadd

I'm having a little trouble with a Solaris package build/install. I have the following entries in my prototype file... # Interfaces file - all versions installed and auto linked to installation type... f none $OPTDIR/config/interfaces.DEV 0444 $OWNER $GROUP f none... (0 Replies)
Discussion started by: JerryHone
0 Replies

6. Linux

Expanding slice

Hi all I am testing backupPC as a backup solution for machines, as far as i knew, backuppc cannot combine more than storage from different slices so it have to be in one slice my question is, what is the easy way to offer a virtual logical drive expanded/expandable to backuppc, i mean i want to... (1 Reply)
Discussion started by: XP_2600
1 Replies

7. Shell Programming and Scripting

expanding alias from a variable

Hi ! I am making my first steps to make a script. Therefore i try to make a scp command more easier. Given is the following alias: 14='admin@x-abcd-def.xyz Now i want to let the script read three var's from the console to use them in the script and then build the scp string. echo... (7 Replies)
Discussion started by: locutus01
7 Replies

8. AIX

expanding the size of vg

Hi, I have created the lun of 15gb and assigned to aix,but now I want to expand the size of lun 15gb to 30gb, I am having following queries. 1)wheather i have to umount that partition on aix side before increasing the size of lun on storage side or directly I can increase directly size... (2 Replies)
Discussion started by: manoj.solaris
2 Replies

9. Shell Programming and Scripting

Expanding shell variable

I have a question about expanding shell variables. Given the following piece of script: a="Some text" b="Other text" for i in a b do string1=$i echo $string1 --> returns 'a' string2=EXPRESSION_WITH_$i echo $string2 --> returns 'Some text' done ... (2 Replies)
Discussion started by: lonar
2 Replies

10. UNIX for Dummies Questions & Answers

tar expanding trouble

Hello, I have just download a .tar.gz when I run: $tar x *.tar.gz or even $tar z *.tar.gz this is the error I get tar: can't open /dev/sa0 : Device not configured How do I reconfigure the device so that it expands the file in it's current location? Thanks so much for your help! (4 Replies)
Discussion started by: TAT2ME74
4 Replies
Login or Register to Ask a Question