The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2003
jyotipg jyotipg is offline
Registered User
  
 

Join Date: Oct 2001
Location: Bangalore
Posts: 95
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
  #2 (permalink)  
Old 10-28-2003
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
See the two Shell Array Variable scripts at context-switch.com - may be helpful.
  #3 (permalink)  
Old 10-29-2003
Simerian Simerian is offline
Registered User
  
 

Join Date: Oct 2003
Location: United Kingdom
Posts: 37
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..
Closed Thread

Bookmarks

Tags
grep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0