Solved

How to add unique folder name to a array in Bash

Posted on 2014-01-27
2
413 Views
Last Modified: 2014-02-01
Following is the details of my program:
containsElement: function which will decide if the 2nd arg contains the 1st arg or not

#!/bin/bash
containsElement () {
  local e
  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  return 1
}

    CL_HOME=${CL_HOME:=/var/lib/data/omfs/certvs/crls/current/crl}
       ARRAY=()
        for i in `find ${CL_HOME} -iname "*.crl"`
          do
            mydir=`dirname $i`
            containsElement "${mydir}" "${Array[@]}"
            if [ $? -eq 1 ]; then
                ARRAY+=("${Array[@]}" "{mydir}")
            fi
        done

        for mydir in `echo ${Unix[@]}`
        do
        #do something with teh variable $mydir
             echo ${mydir}
        done
But all the folders are getting added and i am left with a array with duplicate entries.
0
Comment
Question by:pvinodp
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39811967
ARRAY=(`for i in ${ARRAY[@]} ; do echo $i ; done | sort -u`)
0
 

Author Closing Comment

by:pvinodp
ID: 39827307
thats a crisp solution.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now