The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Determine string in Perl. ejdv Shell Programming and Scripting 4 05-14-2008 04:34 AM
How Can I Easily Determine If A File Has been Added to a Directory goodmis UNIX for Advanced & Expert Users 7 02-04-2007 01:13 AM
How Can I Easily Determine If A File Has been Added to a Directory goodmis UNIX for Dummies Questions & Answers 1 01-31-2007 06:56 PM
cannot determine current directory axes UNIX for Advanced & Expert Users 15 11-13-2006 07:39 AM
determine owner directory permissions from within the directory Sniper Pixie Shell Programming and Scripting 4 03-07-2006 05:06 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
ejdv ejdv is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 46
[Perl] Determine directory name

Hi there,

I wonder if it is possible the determine a name of a directory which is different on various hosts.

Let me try to explain.

I have the directory /tmp/dir1/dir2/canchangedir.
This directory name is different on various hosts.
I need to use the directory name, independent from the host I am on.

This is the directory structure on all hosts (example):

/tmp/dir1
/tmp/dir1/dir2
/tmp/dir1/dir2/canchangedir
/tmp/dir1/dir2/canchangedir/dir3
/tmp/dir1/dir2/file1
/tmp/dir1/dir2/file2
/tmp/dir1/dir2/file3

The name "canchangedir" is different on all hosts.
The structure is the same and the dir1 and dir2 name too.

I tried with find and basename, but did not succeed.

Anyone out there that can do the magic ??

Thanks,

E.J.
  #2 (permalink)  
Old 07-02-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
open the tmp directory and search it?
  #3 (permalink)  
Old 07-03-2009
ejdv ejdv is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 46
Quote:
Originally Posted by KevinADC View Post
open the tmp directory and search it?
@KevinADC,

Okay, a bit short (open it ? search it ? search what ?) , but I think I got it.

Code:
@dir2_contents = </tmp/dir1/dir2/*>;

foreach $item (@dir2_contents) {
  if ( -d $item ) {
    $needed_dir = basename($item);
  }
}

printf "needed_dir = $needed_dir\n";
Sponsored Links
Reply

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 11:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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