I apologize for the non satisfactory context. I did not solve how to use associative arrays as a lookup table and used an ordinary array instead.
Context, operating system, bash version
More than 20 years ago, at the release of bash 2.0, I redefined the cd function and I have used my own version of cd ever since on various solaris, bsd and linux systems. Typing cd without any arguments would list the top 7 directories of DIRSTACK and typing cd with a number argument would change directory using the DIRSTACK. It was slightly annoying that the top of DIRSTACK did not necessarily contain unique directories but my cd function was good enough for usage and I never got around to refining it.
The other day I noticed that bash has evolved and now has associative arrays which I thought would solve the issue with the potentially repetitive directory listing.
The problem
I do not know how to check if a key already exists in an associative array. The exotic ${arr[$i]+7} was something I tried reading
wiki.nix-pro.com/view/BASH_associative_arrays#Check_if_key_exists
The basic algorithm I want to do is
which in a sample test code would be
The above program yields
but what I expected (hoped) it to print was
The workaround
I rewrote my old cd function using a simple array for lookup instead of an associated array. The performance hit is negligible but it is annoying that I could not get the associated array to work. It was not without pain to implement since I haven't done any bash programming in 20 years. My new cd function seems to work all right though I haven't tested it extensively. I provide it here for context.
hi,
I would like to know of a shell script to create the following
A script which will take in two parameters i.e. name of file and SID and create directories named /opt/oracle/admin/$SID/{bdump,cdump,udump}. Then edit the init file and change the three lines that look like this.
... (2 Replies)
I'm trying to iterate a UNIX awk script that returns min/max temperature data for each day from a monthly weather data file (01_weath.dat). The temperature data is held in $5. The temps are reported each minute so each day contains 1440 temperature enteries. The below code has gotten me as far as... (5 Replies)
I have a directory which is /home/mark/files/ , inside this particular I have a bunch of filles (see examples below)
TST_SHU_00014460_20090302.txt
TST_SHU_00016047_20090302.txt
TST_SHU_00007838_20090303.txt
TST_SHU_00056485_20090303.txt
TST_SHU_00014460_20090303.txt... (2 Replies)
Basically, I have a perl script that calls enables one to resume where a video file left off (i.e. where the user stopped playback) that chokes on files that are located in a path that contains spaces.
To make the situation a little more complicated, the perl script gets help from a bash script... (6 Replies)
Hi Experts,
I want to know the count of specific word in a file. I have almost 600+ files.
So I want to loop thru each file and get the count of the specific word.
Please help me on achieving this...
Many thanks (2 Replies)
I am trying to get a listing of ALL directories only under /export (as an example). I can get all the dirs directly under /export but I need any sub dirs under those dirs. I've looked (here and google) but can not find anything that works (4 Replies)
Hi
i need to find x in the following equation such that it satisfies this condition:
y/x-ln(x)-1.24=0
how can i write a script to iterate to give random x to satisfy this equation.
y is different each time too. any help with awk/shell script will be awesome!
thanks (1 Reply)
Hi guys,
I am having trouble with this script. What i want it to do is to iterate all command line arguments in reverse order. The code below does this fine but i need the output to print the words on separate lines instead of one line:
#!/bin/bash
#Takes in the arguments and displays them... (7 Replies)
Have two 3 files which has list of servers,users and location and base url which is common on every server
A = server1 server2 server3
B = user1 user2 user3
C = dom1 dom2 dom3
baseurl=/opt/SP/
and what i have to achieve is below via ssh from REMOTE SERVER
for it's first iteration it... (7 Replies)