Programming :: Using An Array In Bash For Mutiple Paths?

Mar 29, 2011

I'm trying my hand at arrays in bash for a backup script. Now I not sure if this is the correct thing to do and just look at website and amended but does'nt work. Could someone tell me where I'm going wrong

LOG_DIR="/home/ops/Desktop/temp"
array[0]=3
array[1]=/home/ops/Desktop/dir1

[code]...

View 8 Replies


ADVERTISEMENT

Programming :: Auto_extract.sh Bash Script - Does Not Work With Any Paths That Contain Spaces

Jan 25, 2011

Have worked with Linux at home for some time and have wrote the below script.

This script is run when a .torrent file finishes downloading and extracts any .rar files into an extracted directory.

However there are 2 thing that i cannot for the life of me get working.

These are:

1. I need the script to check a txt file to see if the file has been extracted previously.

2. The script does not work with any paths that contain spaces.

Code:

View 11 Replies View Related

Programming :: Bash Array Add Function Example Using Indirect Array Reference As Function Argument?

Jun 20, 2010

I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.

#!/bin/bash
addelementtoarray()
{
local arrayname=$1

[code]....

View 10 Replies View Related

Programming :: Bash Array - More Than One Value Per Item?

Nov 28, 2010

Is it possible to have an array in Bash that can hold more than one value per item?

For example I would like an array like this:

Entry 1: apple, green
Entry 2: banana, yellow

And be able to call the fruit names and their colour in a list. Something like:

for fruit in "${array[@]}"
do
echo a $fruit is $colour
done

If that is possible, is there a limit to values per item? For example some entries in an array could be:

Entry 1: apple, green, round, pips, tree
Entry 2: banana, yellow, long, skin, tree

And I would like to pick out the values such as #3 being "round" and "long".

View 3 Replies View Related

Programming :: How To Copy Array In Bash

May 13, 2010

I have this code:

Code:
original_content=${content[@]};
echo ${#content[@]} # is 23
echo ${#original_content[@]} # is 1

I'd expect original_content should be copy of content. How to copy array?

View 2 Replies View Related

Programming :: Bash String Splitting Into Array?

Oct 14, 2010

I am using gnu bash 3.2I need to split the string into array like

a=this_is_whole_world.file # split [_.]
I need to split this on _ and . some thing like this
a[0]=this
a[1]=is
a[2]=whole
a[3]=world
a[4]=file

preferable using bash regex. if not sed is also ok.

View 2 Replies View Related

Programming :: Bash - Read The Array Dynamically?

Sep 24, 2010

Code:

test=(1 2 3 4 5)
for car in ${test[@]}
do
echo "Element : $car"

[code]....

if variable $car equals 1, new element is added "6" to an array. But i don't know why when i am printing all elements of this array (echo "Element : $car") this element ("6") is not mentioned, but if i make a command which check an amount of contained elements by array it will be 6 elements.

View 14 Replies View Related

Programming :: Using Bash To Append A String To Array?

May 19, 2011

I have the following function that does not iterate through the array I want to be able to do some manipulation on each element in the array[@].it appears the below array has only one item in the array whereas i want the array to have 3 items hence the loop three times printing the message Any ideas why this is not happening ?

function foo() {
name =$1
array=( "$2" )

[code]...

View 5 Replies View Related

Programming :: BASH: Listing Contents Of .zip File Into An Array?

May 18, 2010

I want to list the contents of a zip file amd put each entry into an array. I've been doing

[code]....

View 4 Replies View Related

Programming :: Bash - Searching Strings For Array Elements?

Apr 30, 2010

...and returning the index of the found element in its array.

I have:

for ((i=0; i < ${#array1[@]}; i++)); do
# Read each line of the file test
if [[ $(eval "sed -n '$(($i+1))'p test") == *${array2[0]}* ]]
stuff

I want to find the index of the found substring in array2 and only if it isn't found, move on to the next element of array2. I don't know the size of array2 so that [0] has just got to go.

View 14 Replies View Related

Programming :: Bash: Split A Text File Into An Array?

Sep 18, 2010

I have a file (called twitterstatus.tmp) that looks like this:

Code:

<status>
<id>24854489768</id>
<text>Are we gonna ride the sun home?</text>
<id>55266987</id>

[code].....

How could I feed this into an array, with each element containing everything between the <status> </status> tags?

View 9 Replies View Related

Programming :: Bash To Loop Through Mysql Select Array?

May 26, 2011

I need to know how to assign a result from a select. I am clueless on the sytax. I am trying this in bash. Maybe I am not assigning the array right. It gives me the whole row in the echo instead of just field a. How do I get fieldA = a in the select. Note script was stripped for security on database info but the syntax is same.

Code:

#!/bin/sh
results="$(mysql --user ${DB_USER} -p${DB_PWD} ${DB_NAME} -Bse 'select a,b,c,d from tblMytable')"
for rows in "${results[@]}"
do
fieldA=${rows[0]};
echo ${fieldA};
done

View 2 Replies View Related

Programming :: Bash Unset Array Loops GARBAGE?

Jun 27, 2011

Code:

#loop until there are no more files
while [ ${#files[@]} -gt 0 ]; do
for num in `seq 1 ${#files[@]}`; do
wurd=`tail -4 ${files[$num-1]}`

[code].....

Everything works.. but when it has to unset.. it breaks.. it doesnt give an error though.. it just jams the program.

View 7 Replies View Related

Programming :: Bash - Reading Csv Delimited File To Array And For Further Manipulation?

Jan 6, 2010

I am trying to do this:

1. Read csv delimited file line1 and store all values in array

2. Use the values stored in the array and replace values in other text file with them

3. read line2 in the cvs file and repeat the process

4. Do above for all lines in the cvs file

for example:

file1.cvs content:

text1,text2,text3,"text 4"
a1,a2,3,"a 4"

file.txt content:

some text $array1$ some text
some text $array2$ some text

1. read line 1 - text1,text2,text3,"text 4" put each value in array X[] lines that contain spaces in cvs will have double quotes

2. read x[1] and replace value $array1$ (in file.txt) with x[1]read x[2] and replace value $array2$ (in file.txt) with x[2] and so on

Can above be accomplished in BASH and how?

View 1 Replies View Related

Programming :: Find A Substring/member In A String/array Using Bash?

Oct 13, 2010

This may be a basic bash array/string operation related question, but I couldn't find any direct answer. So here it goes:I have a lot of data sorted in various directories. All directories need same processing except for a special group of directories. I have a symbolic link of the script in discussion in each directory. I want the script to get the name of the current directory, check if that belongs to special group and do specific operations.So I get the name of the directory

Code:
mm=`basename `pwd``
Now the the group of directories that needs something different to be done, contains these

[code]...

View 4 Replies View Related

Programming :: Reading File Permissions Into Bash Array For Processing

Dec 1, 2010

I would like to read unix file permissions into a bash array for processing but tbh I have no idea how to do this. Then I will check for each individual access right l, d, x etc.

View 11 Replies View Related

Programming :: Creating Array From Command Output (Bash Shell Script)

Jan 26, 2011

I have a command that outputs n lines of text, and I want to place each line into an array element, but I can't seem to get the syntax correct

So my command is this:
cat $configfile | sed -n '/cluster:'$clustername'/,/cluster/ p' | awk /host/

Which produces many lines depending on the value of $clustername. I'd like to get each line as elements of an array.

View 5 Replies View Related

Programming :: Parsing Text Files In Bash / Cant Seem To Read The Array Back?

May 29, 2011

PI'm trying to write a script to list all open ports in the MINIUNPND chain in iptables and use the procotol, port and destination ip to open ports on another router using upnpc.Here is the output of iptables -L MINIUPNPD

Code:
>iptables -L MINIUPNPD
Chain MINIUPNPD (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:19955
ACCEPT tcp -- anywhere 192.168.3.124 tcp dpt:20054
ACCEPT tcp -- anywhere 192.168.3.130 udp dpt:10654
ACCEPT tcp -- anywhere 192.168.3.121 tcp dpt:29955
code....

No matter what i do i cant seem to remove the first 4 characters from the MYPROT array to leave only the digits. Also i cant seem to read the array back???

I thought it would simply be a loop reading each line and passing the fields in variables, executing upnpc commands i need then moving to the next line of the file until it reached the EOF.

View 12 Replies View Related

Programming :: Writing Shell Snip To Import CSV Data Into Bash Array

Jan 5, 2011

I have been trying to write a simple snip of bash shell code to import from 1 to 100 records into a Bash array.

I have a CSV file that is structured like:
record1,item1,item2,item3,item4
record2,item1,item2,item3,item4
record3,item1,item2,item3,item4
record4,item1,item2,item3,item4

And would like to get this data into corresponding arrays as such:
$record1[item1-4]
$record2[item1-4]
$record3[item1-4]
$record4[item1-4]

View 9 Replies View Related

Programming :: Change Mutiple Xml Files?

Apr 21, 2010

I'm trying to change a line of a bunch of xml files (more than 800).What I want isto change this line:

Code:
<variable name="reliability" size="1">96</variable>
to

[code]...

View 1 Replies View Related

Software :: Bash - Indirect Array Reference To Array With Values Containing Spaces?

Jun 4, 2010

This _almost_ works. I just can't quite get it to honor the spaces.

Code:

#!/bin/bash
profiles=(
PROFILE_ONE
)
PROFILE_ONE=(setting1 "setting number 2")

[code].....

View 9 Replies View Related

General :: Bash: Calculating In Array And Storing Result In Array?

Dec 2, 2010

I have an array called arrayini which stores numbers. I want to take log to the base 2 of each of the numbers in that array and put it in file called result. I've used the following code to do it.

Code:

size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
echo "scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >result

It works fine but its taking pretty long to calculate since I've got about 230,000 items in the array. So I decided to store the result into an array hoping that it'd be faster. I tried the following code. arrayresult is where I try and store the result. The code doesn't work because of the second last line.

Code:

unset arrayresult
size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
arrayresult[$i]="scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >FILE2

There is a syntax error clearly.

View 6 Replies View Related

Programming :: C Realloc Resize Array / Delete And Add Information Into The Array?

Mar 6, 2011

I am trying to dynamically delete and add information into the array "blah"

Code:
int blahsize = 1;
char** blah = (char**) calloc(blahsize+1,sizeof(char*));
Adding information:
Code:
blah[1]=stuff1;
blah[2]=stuff2;
code....

View 2 Replies View Related

Programming :: Set Different Paths In Makefile?

Oct 8, 2010

at present I compile the same code for different systems (cross compilers)I need to call libs and include paths for the different processors. At present I simply comment out the paths not needed

eg
#INCDIR = -I/cross1/.......
#INCDIR = -I/cross2/.......

[code]....

View 2 Replies View Related

Programming :: Convert Short Array To Char Array?

Jun 7, 2010

I have trouble converting a short array to a char array

Code:

short pShort[4] = { 0x41, 0x42, 0x43, 0x44 };

How to convert this to a char array?

View 4 Replies View Related

Programming :: Converting A PHP Array Into An HTML Array?

Aug 9, 2009

I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.

echo '<input type="hidden" name="delete[]" value="'.$_POST['delete'].'" />';

View 4 Replies View Related

Programming :: Compare Two Filenames Including The Paths?

Jun 22, 2011

I am trying to compare two filenames including the paths. Basically if two paths are similar then my program wants to display message. So I need to check for if two pathnames are same in the sorce and destination. So I was trying for the code to compare tow filename sincluding "" and if the Parent FIle Path is found in the child file path then I need to displays ome message. I was trying to modify something like this:

#!/bin/ksh
# Sample script
file1="C:TextLatestArticleNews.txt"

[code]....

View 7 Replies View Related

Programming :: Non-static Variable $SwitchMap$com$ibot$util$Paths$OS Cannot Be Referenced?

Jul 14, 2010

When i try to compile this file:

Code:
package com.ibot.util;
import java.io.File;

[code]....

View 5 Replies View Related

Programming :: Filling 2D Array With 1D Array In C?

May 26, 2010

(I am using vector() and matrix() functions from "Numerical recipes in C".)There are 100 numbers to be stored in 2D array of 10 rows and 10 columns.100 numbers are stored in a 1D array.I get "segmentation fault" at the line indicated in the segment of my code below:

Code:

:
:
#define size 100
#define nl 1

[code]....

View 12 Replies View Related

General :: Storing Array From Awk In Bash?

Nov 24, 2010

i'm using awk inside bash. i've got an array in awk called arrayinawk. everytime i call another awk command in bash i have to keep creating arrayinawk to work with it. is there anyway i can store arrayinawk in bash and just call the stored value next time i use awk?

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved