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
what is the right syntax ?? convenientstore Shell Programming and Scripting 7 06-04-2007 01:21 AM
csh syntax charlie11k UNIX for Dummies Questions & Answers 0 05-31-2007 11:29 PM
vim and syntax max os kezzol OS X (Apple) 1 04-30-2007 11:22 AM
Help with the syntax chandhar Shell Programming and Scripting 2 03-26-2007 04:38 AM
What does this syntax mean... DrAwesomePhD UNIX for Dummies Questions & Answers 1 07-31-2006 08:54 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-22-2007
Registered User
 

Join Date: Mar 2007
Location: chennai, India
Posts: 9
Help with the syntax

export check=$(expandname $(dirname $(which $0)))
Reply With Quote
Forum Sponsor
  #2  
Old 03-22-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,648
The syntax "command1 $(command2)" will run command2 and read the output from it. This output replaces the characters "$(command2)" and then command1 is run and it will see command2's output as its arguments.

$0 is the first word in the command line used to invoke the current script. This is generally the name of the script.

which $0 will search the PATH environment variable for the full pathname of of the script. So if $0 was "myscript", "which myscript" might return something like "/usr/local/bin/myscript".

dirname $(which $0) returns the directory from a pathname. So "dirname /usr/local/bin/myscript" will return just "/usr/local/bin".

expandname $(dirname $(which $0)) Well, expandname is not a standard or even ubiquitous utility. So your expandname may do something I don't know about. But I have seen expandname and the version I have seen makes limited sense here. The expandname I know about will remove environment variables and shell metacharacters from a pathname. So "expandname /usr/l*l/bin" would probably return "/usr/local/bin". However dirname will never return anything that would need expanding. So this is a wasted step or your version of expandname does something different.

check=$(expandname $(dirname $(which $0))) will take the output from expandname and use it to set the variable "check".

export check=$(expandname $(dirname $(which $0))) And finally the variable "check" is exported into the environment. This means that any child processes that we subsequently spawn will be able to see the value of "check". This represents a small violation of a general coding standard... environment variables are usually all caps. So I would have used CHECK.
Reply With Quote
  #3  
Old 03-25-2007
Registered User
 

Join Date: Mar 2007
Location: chennai, India
Posts: 9
Thanks for ur help
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:43 AM.


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

Content Relevant URLs by vBSEO 3.2.0