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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need explanation Mari.kb UNIX and Linux Applications 1 11-23-2007 06:41 AM
tr explanation please convenientstore Shell Programming and Scripting 1 05-30-2007 08:42 PM
tr explanation please convenientstore Shell Programming and Scripting 0 05-30-2007 08:12 PM
explanation of this line castlerock Shell Programming and Scripting 1 03-22-2006 07:32 PM
AWK explanation penfold Shell Programming and Scripting 2 04-05-2005 06:46 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
Stumble this Post!
explanation for this line

Hi All,

can you please explain me the meaning of this line--

BackupLocation="/inpass/abc"
Parent=$(expr $BackupLocation : '\(.*\)/.*' \| $BackupLocation)

when i ran this as a command also it did not show me anything so could not get the purpose of this line.

Explain it please.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-31-2008
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 954
Stumble this Post!
Here is the ouput under ksh93

Code:
$ BackupLocation="/inpass/abc"
$ echo $BackupLocation
/inpass/abc
$ Parent=$(expr $BackupLocation : '\(.*\)/.*' \| $BackupLocation)
$ echo $Parent
/inpass
$
Note that dirname outputs the same result
Code:
$ dirname /inpass/abc
/inpass
Reply With Quote
  #3 (permalink)  
Old 01-31-2008
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,449
Stumble this Post!
It is an attempt to set the variable Parent. You need to follow it with
echo $Parent
to see anything. Basicly, it strips off a trailing slash followed by some characters. Should the regular expression not match, it just returns the input variable. It will stumble if BackupLocation is set to something like "/abc" which matches the regular expression without returning anything. But that input may not be likely. My preferred solution
Parent=${BackupLocation%/*}
would have the same trouble. A better solution might be:
Parent=$(dirname $BackupLocation)
which should work all the time.
Reply With Quote
  #4 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 285
Stumble this Post!
Thanks Guys for all your valuable comments.I got it now.

Thanks
Namish
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0