QUOTE(handle1982 @ 26 Sep, 2009 - 02:51 AM)

I have a code where they assigning
Which is as below
$AVAILABLE_SPACE = `df -b $UNLOAD_PATH | cut -d':' -f2 | awk '{print $1}'`;
Where AVAILABLE_SPACE is shell variable which will hold the value for disk space available in the path mentioned by variable UNLOAD_PATH
My question is
1. df -b $UNLOAD_PATH (what actually does it calculates free space in the path mentioned by the variable $UNLOAD_PATH but why it is required?? I can give you the clear picture of my understanding about df command is something as below
It calculates the free disk space available in hard drive?
Now i am not able to understand why we are calculating the free disk space in the particular path as in the above example we are calculating the free disk space available in the path mentioned by the variable UNLOAD_PATH. Why the free disk space varies from path to path. I thought irrespective of the path where we want to calculate the free disk space df command will give the free disk space of the hard drive it should not vary from one path to other path
2.cut -d':' -f2 (Where is the file name associated with the ut command)
3.awk '{print $1}'` (1.i don't have any idea about awk coomand can you please explain it.2.Why are we using print command inside awk command. 3. What is $1 )
I'll try and answer them in order:
1. df will calculate file system usage, not free space. You probably normally use it to calculate the free space left on a drive. Since you are defining $UNLOAD_PATH, I'm going to make the assumption that $UNLOAD_PATH is a mount point (like a drive letter in Windows, a mount point can be either a directory OR a partition/drive in *nix).
2. cut is cutting the output. -d tells it to look for a delimiter (normally a space, but you're defining a : instead here) and -f is how many positions to jump. So you your output was 1:2:3:4 tihis cut command would display the number 2, since it's cutting the "word" up into pieces by cutting at the : character, then displaying the 2nd position (the number 2).
3. awk is a pattern matching and text processing program. You can use it to search/replace words in a text file, find specific words, etc. You are using the print command in awk because you want it to print something. awk (mawk really) has it's own little language that you can write programs in. You're issuing it the print command here, and $1 if the first word sent to it, which is usually the filename supplied to it. In shell scripting, if you gave the command:
process.sh myfile
myfile would be $1 (automatically) for the process.sh script. You could call $1 inside your process.sh script and it would be myfile.
Hope that helps some. The best friend you'll get with this is going to be the man pages. At a command prompt, type:
man awk
And it will display the manual pages for the awk command. Every command *should* have a man page.