|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
meaning of ${0%${0##*/}}
. ${0%${0##*/}}Script_Name
if i issue this command, it is executing the script. can any one tell what is the meaning of ${0%${0##*/}} |
| Sponsored Links | ||
|
|
|
|||
|
That's a sequence of two variable substitutions.
${var##string} returns $var with the longest possible prefix matching string removed ${var%string} returns $var with the shortest possible suffix matching string removed Combined, these return the path name component from $0 which is the name of the currently running script. In other words, the construct attempts to find the file Script_Name from the same directory where the current script is running from, and execute it using the shell's source (dot) command. This is a common technique for including a snippet of shared code from another file into a shell script. |
|
|||
|
Thanks... That was really very helpful... I came to know the meaning of ${var##string} and ${var%string}.
if i am in some XYZ dir. I have 2 scripts, Script1 and Script2 in it. To call Script2 from Script1, I can use . ${0%${0##*/}}Script2 or . ./Script2 Both do the same job. then why use this ". ${0%${0##*/}}Script2" instead of simply using ". ./Script2"? Last edited by nyelavarthy; 09-22-2008 at 06:31 AM.. |
|
|||
|
Code:
$ temp=/u/ppattusa/unix
$ echo ${temp%${temp##*/}}
OUTPUT
/u/ppattusa/
pls see the above example, temp having some path and and the substitution will return the base path. I think to pass the path as parameter they used like that. If you provide the script1 code sample, then it will be easy to find for wat purpose they using like that. |
|
|||
|
Quote:
Code:
$ cd /some/dir $ /some/other/dir/script $ _ inside your script the "./" will expand to the PWD, which is not where the script is stored but where you have been when starting the script - "/some/dir" in the example, not "/some/other/dir". If you now execute Code:
. ./script2 you will execute "/some/dir/script2" instead of "/some/other/dir/script2". Still $0 will contain "/some/other/dir/script" and subsequently the expansion will find script2 on its correct place. As a rule of thumb: avoid relative paths like the plague in scripts. Always use absolute paths to make sure you end up where you suppose to end up. I hope this helps bakunin |
|
|||
|
scripts adminBuildDomain and crstEnv are in the same directory. from this directory only we run all the scripts.
adminBuildDomain calls crstEnv Code in adminBuildDomain is: . ${0%${0##*/}}crstEnv ${0%${0##*/}}crstEnv returns crstEnv value since the directory path where we run the scripts is same as the directory where the scripts are present, we can use . ./crstEnv instead of . ${0%${0##*/}}crstEnv i really dont understand the importance of ". ${0%${0##*/}}crstEnv" in this case. i dont understand why ". ${0%${0##*/}}crstEnv" is used instead of ". ./crstEnv" |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| meaning of .& in shell | scorpio | UNIX for Dummies Questions & Answers | 1 | 06-05-2008 02:10 AM |
| if [ ! -r ${1} ] meaning in ksh | naveeng.81 | Shell Programming and Scripting | 1 | 04-09-2008 02:47 PM |
| Meaning of % sign | sokash | Shell Programming and Scripting | 2 | 06-09-2006 12:30 PM |
| Whats the meaning | dhananjaysk | Shell Programming and Scripting | 7 | 03-16-2006 09:43 AM |
| what is the meaning here? | forevercalz | Shell Programming and Scripting | 2 | 09-29-2005 01:46 PM |