Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to add unique folder name to a array in Bash

Posted on 2014-01-27
2
Medium Priority
?
442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 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