Sponsored Content
Top Forums Shell Programming and Scripting Bash parameter expansion from a config file Post 302515575 by Corona688 on Wednesday 20th of April 2011 12:19:01 PM
Old 04-20-2011
This doesn't work because bash doesn't substitute twice. If you have a string with "$varname" in it, it won't go back and start over and realize you also wanted $varname to be evaluated, too!

To do that kind of doublethink, you have to stuff it into an eval.

ARGS="$(eval $stringwithvarinit)"

Beware that you can do anything in an eval. Someone could stuff an `rm -rf ~/` in your config file and it could run it.
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

removing html tags via parameter expansion

Hi all- I have a variable that contains a web page: echo $STUFF <html> <head> <title>my page</title></head> <body> blah blah etc.. Can I use the shell's parameter expansion abilities to remove just the tags? I thought that FIXHTML=${STUFF//<*>/} might do it, but it didn't seem to... (2 Replies)
Discussion started by: rev66
2 Replies

2. Shell Programming and Scripting

Need help with parameter expansion

Say you have this numeric variable that can be set by the user but you never want it to leave a certain range when it gets printed. How could you use parameter expansion such that it will never expand outside of that boundary? Thanks ---------- Post updated at 11:09 PM ---------- Previous update... (3 Replies)
Discussion started by: stevenswj
3 Replies

3. Shell Programming and Scripting

Parameter expansion not working for all strings...

I'm trying to write a script that parses my music collection and hard link some filenames that my media player doesn't like to other names. To do this I need to extract the name and remove alla non ASCII characters from that and do a cp -l with the result. Problem is this: 22:16:58 $... (8 Replies)
Discussion started by: refuser
8 Replies

4. UNIX for Dummies Questions & Answers

Parameter Expansion with regular expression

Hello experts, I am exploring parameter expansion, and trying to cut the fields in a URL. Following is the requirement: I have // abc.nnt /dir1/dir2/dir3/dir4/somefile.java What i need to get is the path after dir3, and dir3 will be passed. output that i need is... (1 Reply)
Discussion started by: gjarms
1 Replies

5. Shell Programming and Scripting

Bash Parameter Expansion

I have made the following examples that print various parameter expansions text: iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018.sac (text%.*): iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018 (text%%.*): iv-hhz-sac/hpac/hhz (text#*.): d/iv.hpac..hhz.d.2016.250.070018.sac... (2 Replies)
Discussion started by: kristinu
2 Replies

6. Shell Programming and Scripting

Bash Parameter Expansion

#!/bin/bash SNMPW='/usr/bin/snmpwalk' while read h i do loc=$($SNMPW -v3 -u 'Myusername' -l authPriv -a SHA -A 'Password1' -x AES -X 'Password2' $i sysLocation.0 2>/dev/null) loc=${loc:-" is not snmpable."} loc=${loc##*: } loc=${loc//,/} echo "$i,$h,$loc" done < $1 My question is ... ... (1 Reply)
Discussion started by: sumguy
1 Replies

7. Shell Programming and Scripting

Bash : More parameter expansion and IFS

I am trying to become more fluent with the interworking of bash and minimize the number of external calls. Sample Data. This will be the response of the snmp query. SNMPv2-MIB::sysName.0 = STRING: SomeHostName SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.1745... (5 Replies)
Discussion started by: sumguy
5 Replies

8. UNIX for Beginners Questions & Answers

How to Grep second word in config file using parameter?

Currently i am building one script to grep region records in the config file based on parameter and then i am creating a text file with that out put and i am reading the source file path in that out put file now i need to pass one more parameter like module based upon that it has to create a... (1 Reply)
Discussion started by: saranath
1 Replies

9. Shell Programming and Scripting

Bash : Parameter expansion ${var:-file*}

Example data $ ls *somehost* 10.10.10.10_somehost1.xyz.com.log 11.11.11.11_somehost2.xyz.com.log #!/bin/bash #FILES="*.log" FILES=${FILES:-*.log} for x in $FILES do ip="${x%%_*}" # isolate IP address x="${x##*_}" # isolate hostname hnam="${x%.*}" # Remove the ".log"... (2 Replies)
Discussion started by: popeye
2 Replies

10. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies
1'

ns_cache(3aolserver)					    AOLserver Built-In Commands 				      ns_cache(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_cache - Cache arbitrary data SYNOPSIS
ns_cache append cachename key string ?string ...? ns_cache create cachename ?-size maxsize? ?-timeout timeout? ?-thread thread? ns_cache eval cachename key script ns_cache flush cachename key ns_cache get cachename key ?varname? ns_cache incr cachename key ?value? ns_cache lappend cachename key string ?string ...? ns_cache names cachename ?pattern? ns_cache set cachename key string _________________________________________________________________ DESCRIPTION
AOLserver implements a C API for caching arbitrary data. This module provides a Tcl API on top of the C API. A cache, in this context, is simply a dictionary that maps keys to values. Keys are always stored as NUL-terminated strings. How values are stored depends on the type of cache. ns_cache create cachename ?-size maxsize? ?-timeout timeout? ?-thread thread? This command creates a new cache named cachename. If -thread is given and is true, then it is a thread-private cache. Otherwise it is a global cache. If maxsize is given, then it is a sized-based cache. If timeout is given, then it is a timeout-based cache. Oth- erwise, it is a timeout-based cache with an infinite timeout, meaning it will never be flushed. This command returns nothing if it is successful. ns_cache eval cachename key script This command atomically sets and gets a cache value. First, it looks up key in the cache named cachename. If it finds an entry, it returns the value of that entry. Otherwise, it executes script, stores the return value in the cache, and also returns that value. Script may optionally use the return command to return its value. For example, this will store the value "2" in mycache, if mykey is not already present: ns_cache eval mycache mykey { expr {1+1} } This will also store the value "2" in mycache: ns_cache eval mycache mykey { return [expr {1+1}] } If script raises an error, or exits with break or continue, then ns_cache eval simply returns the same condition without modifying the cache. ns_cache flush cachename key This command removes the entry for key from the cache named cachename. If the cache has no entry for key, then nothing happens. For global caches, ns_cache flush interacts with ns_cache eval. Suppose thread 1 has called get_thing A and is executing the long operation to compute the value for A. Thread 2 calls get_thing A and starts waiting for thread 1 to finish. Thread 3 calls ns_cache flush thing_cache A. Thread 1 will continue executing the long operation, but thread 2 will also start the long operation. When thread 1 completes the long operation, ns_cache eval returns the (now stale) value it computed, but it does not store the value in the cache. When thread 2 completes the long operation, ns_cache eval stores the (fresh) value it computed in the cache and returns the fresh value. ns_cache get cachename key ?varname? This command looks up key in the specified cache. It operates differently depending on whether varname was given. If varname absent and the key exists the value is returned and if the key is missing an error is raised. If varname is provided and the key exists the command sets varname to the value and returns 1, otherwise it returns 0. ns_cache names cachename ?pattern? This command returns a list of all keys currently in the specified cache. If pattern is specified, only matching entries are returned (match pattern syntax like in string match). If the cache is thread-private, then the list only includes keys that are in the thread's private cache. ns_cache set cachename key value This command stores value for key in the specified cache. CACHE TYPES
ns_cache supports three types of caches: Global Size-Limited Cache ns_cache create cachename -size maxsize Entries in a cache of this type are accessible to all threads. Each cache has its own mutex that protects access to its entries. Cache values are stored as counted strings, so arbitrary binary data can be cached. A global cache stores strings instead of Tcl objects to prevent race conditions that could lead to heap corruption. The cache has a maximum size specified when the cache is created. The size of the cache is the sum of the sizes of all the values in the cache; keys do not count toward a cache's size. If inserting a value into the cache makes the cache's size exceed its maximum, then cache entries are evicted starting with the least-recently used entry until the size is below the maximum size (or until only the new value remains in the cache). Global Time-Limited Cache ns_cache create cachename -timeout timeout Entries in a cache of this type are accessible to all threads. Each cache has its own mutex that protects access to its entries. Cache values are stored as counted strings, as in a global size-limited cache. The cache has a maximum entry lifetime, called its timeout, specified (in seconds) when the cache is created. Every timeout seconds, AOLserver flushes all cache entries that have not were not created or accessed in the last timeout seconds. Thread-Private Size-Limited Cache ns_cache create cachename -size maxsize -thread 1 Each thread in AOLserver automatically gets its own private cache named cachename. Since a thread-private cache is only accessed by one thread, access to it does not require a mutex. Entries in one thread's cache are not visible to any other thread. Cache values are stored as Tcl objects. When a value is stored in the cache, nscache computes its string form and uses the length of the string as the size of the value. The cache has a maximum size, like a global size-limited cache. However, because of the way the cache value sizes are computed, the actual memory usage of the cache values may be several times larger than maxsize. Thread-private caches may offer higher performance if the cached values are complex objects such as lists or scripts, but require more storage than global caches. SEE ALSO
Ns_Cache(3), nsv(n) AOLserver 4.0 ns_cache(3aolserver)
All times are GMT -4. The time now is 07:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy