How to maintain the content of array in any directory I go?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to maintain the content of array in any directory I go?
# 1  
Old 02-24-2009
How to maintain the content of array in any directory - pliz helppp!

Hi all,

I have this scenario where:-



The file that I want to save its name into array df[1] is my.08120323.trx which is located in the dir as below:

$ pwd

/u01/abc/def/SRC_datafiles

$ ls *trx

my.08120323.trx

$ df[1]=*"trx" ##keeping the filename my.08120323.trx into df[1]

$ echo ${df[1]}

my.08120323.trx ##getting the correct full output



I want $df[1] content - my.08120323.trx to be maintained in any directory that I go.. example below directory.. but I only got *trx value as below when I echo ${df[1]}

$ cd ../..

$ pwd

/u01/abc

$ echo ${df[1]}

*trx ##this is not the output that i expected.. i want it to show my.08120323.trx

$



How do I maintain the value of df[1] to be my.08120323.trx instead of only *trx in any directory I go?

Please shed some light.

Thanks!

Last edited by luna_soleil; 02-24-2009 at 01:44 PM..
# 2  
Old 02-25-2009
Code:
$ df[1]=$( echo *trx ) ##keeping the filename my.08120323.trx into df[1]

$ echo ${df[1]}

The problem is the parsing sequence of the shell.

Variable assignment occurs before file metacharacter expansion.

In both cases, the value of df[1] is actually only *trx.
When there is a file that matches that pattern,
the shell expands to show the matching files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: how compare content of a file with an other array

Hi, I created a skript in ksh which generate a file with semicolon as separator, this is an example of the file a created: example content file: hello;AAAA;2014-08-17 hello;BBBB;2014-08-17 hello;CCCC;2014-08-17 I would need to compare the content in of the second column of this file... (3 Replies)
Discussion started by: jmartin
3 Replies

2. Shell Programming and Scripting

[solved] awk: test assoc. array for content

Hi all, I am looking for a quick/short way in awk to check if an associative array has any content. I know I can split() it to an indexed array and check if the 1st element is set, or cycle through it with something like for( ele in arr ), but I want to avoid that, as I am looking for a shorter... (3 Replies)
Discussion started by: zaxxon
3 Replies

3. Shell Programming and Scripting

Print @array content to a file

Hi, as the title, I have an array @f_lines with gene information in it. How can I put the content of @f_lines into a file so that I can read it? I tried this: open(OUTPUT, "file"); # put gene information in this file; @f_lines = ("gene1", "gene2", "gene3"...); # gene information; print... (3 Replies)
Discussion started by: lyni2ULF
3 Replies

4. Shell Programming and Scripting

Store content from array to Spread_sheet using perl

How to store the content from array to either "row-column" or "column-row" order? (0 Replies)
Discussion started by: kavi.mogu
0 Replies

5. Shell Programming and Scripting

How to list the content of a directory

Hi I want to write a script that reads a directory name, checks if the directory exists and lists the content of that directory. That's what I have at the moment. function listDirectory { echo "Give in a directory name" read name #Here I want to check if the... (4 Replies)
Discussion started by: hss
4 Replies

6. UNIX for Dummies Questions & Answers

Move content from directory to another

I have in root directory a folder A and a Folder B. I want to copy or move all content (many files) from A to B. How do I do that UNIX style? Thanks! (6 Replies)
Discussion started by: Matsakii
6 Replies

7. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

8. Shell Programming and Scripting

How to maintain wildcard array variable

Hi all, I have this scenario where:- The file that I want to save its name into array df is my.08120323.trx which is located in the dir as below: $ pwd /u01/abc/def/SRC_datafiles $ ls *trx my.08120323.trx $ df=*"trx" ##keeping the filename my.08120323.trx into df $... (2 Replies)
Discussion started by: luna_soleil
2 Replies

9. Shell Programming and Scripting

file content in an array PERL

Hello everybody, I'm new in this forum. I searched a long time for a solution for my problem but I didn't find the right thing. I have to read from a file (content is "abngjm" without any other signs) and have to write this content in an array. But every sign has to be called by its own... (5 Replies)
Discussion started by: e_prof
5 Replies

10. Shell Programming and Scripting

convert variable content to array

Hi All, I have a variable in a shell script which holds let say n paarmeteres with space separate them : $var = par1 par2 par3 par4 parn; so if I print this variable this is what I'll see: par1 par2 par3 par4 parn I need to insert each parameter to an array , so I can go over on each... (3 Replies)
Discussion started by: Alalush
3 Replies
Login or Register to Ask a Question