Sponsored Content
Top Forums Shell Programming and Scripting Iterate over `dirs` in a bash script Post 303033157 by RudiC on Sunday 31st of March 2019 11:55:26 AM
Old 03-31-2019
Wow, that's intricate and certainly beyond me on first sight. A few comments:
- You don't need to check if an index is already represented in an associative array; just assign it. If it's aready there, it's overwritten, if not, added.
- your cd without parameter naturally lends itself to bash's select statement; see below (as a proof of concept; it just echoes the cd, no error checking etc.). Note the duplicate /usr entry:



Code:
echo ${DIRSTACK[@]}
/usr /etc/network /home/myuser /usr /mnt/9/plgr
declare -A TMP
for DN in ${DIRSTACK[@]}; do TMP[$DN]=1; done
select R in ${!TMP[@]}; do echo cd $R; break; done
1) /usr
2) /home/myuser
3) /etc/network
4) /mnt/9/plgr
#? 3
cd /etc/network


Last edited by RudiC; 03-31-2019 at 01:38 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to create dirs

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)
Discussion started by: sjajimi
2 Replies

2. UNIX for Dummies Questions & Answers

Iterate a min/max awk script over time-series temperature data

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)
Discussion started by: jgourley
5 Replies

3. Shell Programming and Scripting

script find files in two dirs HELP

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)
Discussion started by: fierusbentus
2 Replies

4. Shell Programming and Scripting

perl script chokes on dirs with spaces

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)
Discussion started by: audiophile
6 Replies

5. UNIX for Advanced & Expert Users

script to recursively change permissions on file and dirs differently?

Hi there, I need to change all files/dirs 1. all files with 744 2. all dirs with 755 is there a script for that ? thanks, thegunman (13 Replies)
Discussion started by: TheGunMan
13 Replies

6. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

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)
Discussion started by: elamurugu
2 Replies

7. UNIX for Dummies Questions & Answers

**HELP** how to do a listing of dirs and all sub dirs only

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)
Discussion started by: bbraml
4 Replies

8. Shell Programming and Scripting

script to iterate

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)
Discussion started by: saint2006
1 Replies

9. UNIX for Dummies Questions & Answers

Script to iterate all command line arguments

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)
Discussion started by: pipeline2012
7 Replies

10. UNIX for Beginners Questions & Answers

Script to iterate over several options

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)
Discussion started by: abhaydas
7 Replies
MSSQL_FETCH_ASSOC(3)													      MSSQL_FETCH_ASSOC(3)

mssql_fetch_assoc - Returns an associative array of the current row in the result

SYNOPSIS
array mssql_fetch_assoc (resource $result_id) DESCRIPTION
Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mssql_fetch_assoc(3) is equiv- alent to calling mssql_fetch_array(3) with MSSQL_ASSOC for the optional second parameter. PARAMETERS
o $result_id - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows. EXAMPLES
Example #1 mssql_fetch_assoc(3) example <?php // Send a select query to MSSQL $query = mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]'); // Check if there were any records if (!mssql_num_rows($query)) { echo 'No records found'; } else { // Print a nice list of users in the format of: // * name (username) echo '<ul>'; while ($row = mssql_fetch_assoc($query)) { echo '<li>' . $row['name'] . ' (' . $row['username'] . ')</li>'; } echo '</ul>'; } // Free the query result mssql_free_result($query); ?> PHP Documentation Group MSSQL_FETCH_ASSOC(3)
All times are GMT -4. The time now is 11:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy