Decipher Script

Hi Guys,

I am running solaris and I need help in deciphering the following commands:

dir_t1=`echo $0|nawk -F'/' '{print NF}'`
dir_t2=`expr $dir_t1- 1`
dir_t3=`echo $0|cut -d'/' -f1-$dir_t2`
export dir_t2

What will be the value for dir_t3?

Please help !!!!!!!!!!!!!!!

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 08:20 AM ---------- Previous update was at 08:18 AM ----------

Wouldn't it be easier to simply run the script and see what it does?

Thanks for the reply and the comments.

I should also note that those commands are inside the script.

I can't test the script as the script exists on production system.

I just want to get the interpretation of those commands then I will be able to get the gist of the script.

Thanks

My guess: the directory containing the script executed ...

[house@universe] more Desktop/test.sh
#! /bin/bash
echo $0
dir_t1=`echo $0|nawk -F'/' '{print NF}'`
echo $dir_t1
dir_t2=`expr $dir_t1 - 1`
echo $dir_t2
dir_t3=`echo $0|cut -d'/' -f1-$dir_t2`
echo $dir_t3
exit 0
[house@universe] sh Desktop/test.sh
Desktop/test.sh
2
1
Desktop

dr.house is right.
The end product is the same as this single line which finds the directory name of the command used to invoke the script:

dir_t3="`dirname $0`"

If the script was started with a full path name, the output is the full path of the directory containing the script. If the script was started with "./scriptname", the output is just "." .

Thanks a lot for the reply...