![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible to draw table/matrix using shell script? | jakSun8 | Shell Programming and Scripting | 2 | 03-18-2009 10:53 PM |
| Creating a Hash Table | callmetheskull | High Level Programming | 4 | 12-23-2007 03:17 PM |
| hash table implementations in C Language | vlrk | High Level Programming | 11 | 07-15-2007 09:33 AM |
| Alter Table Shell Script | ankitgupta | Shell Programming and Scripting | 2 | 10-06-2006 06:01 AM |
| Reading a table in a shell script | luiscarvalheiro | Shell Programming and Scripting | 13 | 08-10-2006 06:16 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
|||||
|
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 08:10 AM.. |
![]() |
| Bookmarks |
| Tags |
| grep or |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|