The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to maintain the content of array in any directory I go? luna_soleil UNIX for Dummies Questions & Answers 1 02-25-2009 11:55 AM
sql variable as array index sudheer157 UNIX for Advanced & Expert Users 1 02-06-2009 06:26 PM
How To Pass an Array Variable msb65 UNIX for Dummies Questions & Answers 9 09-04-2008 02:48 PM
Array help (variable substitution). dsimpg1 Shell Programming and Scripting 3 04-11-2007 05:38 PM
Find wildcard .shtml files in wildcard directories and removing them- How's it done? Neko UNIX for Dummies Questions & Answers 1 06-27-2001 10:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-25-2009
luna_soleil luna_soleil is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 33
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[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 in below directory.. but I only got *trx value as below when I echo ${df[1]} when I go this directory:

$ 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!
  #2 (permalink)  
Old 02-25-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250

Code:
$ cd /tmp
$ touch my.08120323.trx
$ df[1]=`echo *trx`
$ echo ${df[1]}
my.08120323.trx
$ cd /
$ echo ${df[1]}
my.08120323.trx

You are storing the '*' wildcard in df[1] instead of the filename so when you do the "echo ${df[1]}", that's the point where filename matching happens. If there is no matching file in the directory, it will show "*trx". Storing the output of "echo *trx" eliminates this issue.
  #3 (permalink)  
Old 02-25-2009
luna_soleil luna_soleil is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 33
Quote:
Originally Posted by rikxik View Post
Code:
$ cd /tmp
$ touch my.08120323.trx
$ df[1]=`echo *trx`
$ echo ${df[1]}
my.08120323.trx
$ cd /
$ echo ${df[1]}
my.08120323.trx

You are storing the '*' wildcard in df[1] instead of the filename so when you do the "echo ${df[1]}", that's the point where filename matching happens. If there is no matching file in the directory, it will show "*trx". Storing the output of "echo *trx" eliminates this issue.

Hey this is working! Thank you so much rikxik! Really really really appreciate this as I've been scratching my head from yesterday abt this issue
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0