[Wolves] Arrays within Bash

Re-LoaD reload at brum2600.net
Thu Jul 28 11:51:21 UTC 2011


not sure what you mean but will this help :---

Cheers
Reload
----
reload at orac:~$ cat myfile.txt
BP1_FS1='bp1_usr /usr/BP1'
BP1_FS2='bp1_mnt /mnt/BP1'
BP1_FS3='bp1_ora /oracle/BP1'
BP1_FS4='bp1_data /oracle/BP1/data'
BPA
HELLO
TEST
BLAH

reload at orac:~$ cat myscript.sh
#!/bin/bash
stuffarray=(` cat myfile.txt | awk '$0~"BP1_FS" {print $0}'` )

echo ${stuffarray[@]}



reload at orac:~$ ./myscript.sh
BP1_FS1='bp1_usr /usr/BP1' BP1_FS2='bp1_mnt /mnt/BP1' BP1_FS3='bp1_ora 
/oracle/BP1' BP1_FS4='bp1_data /oracle/BP1/data'
reload at orac:~$











---:

On 28/07/2011 11:52, Simon Burke wrote:
> Hi guys,
>
> The list has been quiet this recently so I thought I'd put forward
> this conundrum.
> I have a file that is formatted in a similar fashion to:
>
> BP1_FS1='bp1_usr /usr/BP1'
> BP1_FS2='bp1_mnt /mnt/BP1'
> BP1_FS3='bp1_ora /oracle/BP1'
> BP1_FS4='bp1_data /oracle/BP1/data'
>
> The problem is that I need to loop through all the items that start
> with BP1_FS in another script. I have tried to pull them out into an
> array so I can loop through them, but the problem I am having is that
> the the records in the array are being split into "'bp1_usr"
> "/usr/BP1" and so forth.
>
> It seems to be splitting the records at any occurance of a space, but
> I need that space left in, and for everything in the quote marks to be
> a separate records.
>
> Can anyone suggest either a better way of doing this, or how I can get
> around my array problem. Please note that although I'd like to just
> use python, it has to be a bash script.
>
> Regards,
> Simon.
>
> _______________________________________________
> Wolves LUG mailing list
> Homepage: http://www.wolveslug.org.uk/
> Mailing list: Wolves at mailman.lug.org.uk
> Mailing list home: https://mailman.lug.org.uk/mailman/listinfo/wolves
>




More information about the Wolves mailing list