LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-20-2004, 07:04 PM   #1
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Rep: Reputation: 0
Searching through arrays


I'm trying to create a shell script using my, very basic, shell scripting skills.

I work at a Mac Lab that has different sections of computers with different types of software in each section. I'm trying to write a shell script that will take arguments, search either a seperate file or just already set arrays in the script, and then spit out an answer based on the given arguments.

I have my arrays set up in a file so far in the form of section='SoftwareA SoftwareB SoftwareC etc...' and I can grab arguments, but I'm starting to get stuck now. I don't know how to take the arguments and search each array. What I have so far is here:
Code:
#!/bin/bash
#set -A args $*

# Script to find software

section1=(SoftwareA SoftwareB SoftwareC SoftwareD SoftwareE)
section2=(SoftwareA SoftwareC SoftwareD SoftwareE)
section3=(SoftwareA SoftwareB SoftwareE)
section4=(SoftwareA SoftwareB SoftwareC SoftwareD)
*edit, I apparently can do arrays through bash, I thought you couldn't. So I changed to bash.

Last edited by Benr; 09-20-2004 at 07:19 PM.
 
Old 09-21-2004, 02:50 PM   #2
Benr
LQ Newbie
 
Registered: Jan 2004
Posts: 12

Original Poster
Rep: Reputation: 0
heh, guess I shouldn't have posted in such a high traffic thread.

Here's what I have so far:

Code:
#!/bin/bash

for $* in
do
grep -i $* section1
grep -i $* section2
grep -i $* section3
grep -i $* section4
done

section1=(SoftwareA SoftwareB SoftwareC SoftwareD SoftwareE)
section2=(SoftwareA SoftwareC SoftwareD SoftwareE)
section3=(SoftwareA SoftwareB SoftwareE)
section4=(SoftwareA SoftwareB SoftwareC SoftwareD)
I have 4 files with each piece of software acting as my arrays(?) So there is a file section1 with
SoftwareA
SoftwareB
SoftwareC

Should I be greping each file for $* (the agruments entered)? Can I take agruments entered and search the array's for them?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument Arrays saiz66 Programming 3 09-29-2004 11:55 PM
Arrays in C++ kalleanka Programming 5 02-07-2004 01:27 AM
help with arrays leroy27336 Programming 6 01-20-2004 07:07 PM
arrays in perl BBQ_Matt Programming 3 09-23-2003 08:45 AM
C. Arrays and Letters? Gerardoj Programming 1 09-22-2003 02:15 AM


All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration