![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible to draw table/matrix using shell script? | jakSun8 | Shell Programming and Scripting | 0 | 03-13-2008 06:53 AM |
| Creating a Hash Table | callmetheskull | High Level Programming | 4 | 12-23-2007 11:17 AM |
| hash table implementations in C Language | vlrk | High Level Programming | 11 | 07-15-2007 06:33 AM |
| Alter Table Shell Script | ankitgupta | Shell Programming and Scripting | 2 | 10-06-2006 03:01 AM |
| Reading a table in a shell script | luiscarvalheiro | Shell Programming and Scripting | 13 | 08-10-2006 03:16 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Creating a hash table using shell script
Hi,
For one of my programs, I need to have a hashtable as in Perl. Unfortunately shell doesnt provide any variable like hash. Is there anyway/trick, I could implement a hash in shell (using shell scripts/sed/awk). JP |
| Forum Sponsor | ||
|
|
|
||||
|
See the two Shell Array Variable scripts at context-switch.com - may be helpful.
|
|
|||
|
Faked Hash
You could fake a hash using a pseudo-associative array. AWK provides this facility but it involves a little work in the ksh, for example:
Storing a value using a variable as a key: where n="TEST" typeset val_${n}=3 the value of ${val_TEST} will be seen to be 3, checked using set or env. Reading the value is a little trickier. It can be performed directly if the key name is constant: echo "${val_TEST}" However, to use a variable key, perform the following: echo "$(eval echo \$val_${n})" This acts as a pointer and should then return 3. In order to run the hash, set or env can be used along with a pattern matching utility, i.e. grep or egrep, especially if the variable name prefix is very specific (i.e. val_). Last edited by Simerian; 10-29-2003 at 04:10 AM. |
|||
| Google UNIX.COM |