LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   learning korn shell (https://www.linuxquestions.org/questions/linux-newbie-8/learning-korn-shell-850406/)

Madison00 12-15-2010 09:22 AM

learning korn shell
 
I am learning ksh shell and have question, below is the command and I am not clear exactly it mean:

#!/bin/ksh
ScriptDir=`dirname $0`


1. does it mean they want to set ScriptDir variable to dirname?
2. $0: is it standard input?

3. I have been reading a lot of book and able to understand each seperate command, my problem is I have a hard time to put all of the command together. any recommendations?

Thanks

druuna 12-15-2010 09:36 AM

Hi,
Quote:

Originally Posted by Madison00 (Post 4192415)
I am learning ksh shell and have question, below is the command and I am not clear exactly it mean:

#!/bin/ksh
ScriptDir=`dirname $0`


1. does it mean they want to set ScriptDir variable to dirname?

dirname $0 is between backticks, which means that it (dirname $0) is executed and the content is put into the SCriptDir variable.

Quote:

2. $0: is it standard input?
$0 holds the name of the script itself. $1, $2, $N are the "input" you give when starting a script.
I.e: myscript.ksh foo bar -> $0 will be myscript.ksh, $1 would be foo and $2 bar.

Quote:

3. I have been reading a lot of book and able to understand each seperate command, my problem is I have a hard time to put all of the command together. any recommendations?
KSH has some dialects and it depends a bit on which you use. I like Learning the Korn Shell by O'Reilly (ISBN 1-56592-054-6) it focusses on ksh88.

Hope this helps.

barriehie 12-15-2010 09:46 AM

Quote:

Originally Posted by Madison00 (Post 4192415)
I am learning ksh shell and have question, below is the command and I am not clear exactly it mean:

#!/bin/ksh
ScriptDir=`dirname $0`


1. does it mean they want to set ScriptDir variable to dirname?
2. $0: is it standard input?

3. I have been reading a lot of book and able to understand each seperate command, my problem is I have a hard time to put all of the command together. any recommendations?

Thanks

1. dirname strips the non-directory suffix from the file name. i.e. /home/your_login/filename >> /home/your_login.
2. $0 is the first element on the command line, $1 is the next one, $2 is after that, ... up to $9 and then things change.

Code:

$ > man dirname
will explain the dirname command. You can do 'man whatever' to read the manpage on a command.

HTH,


All times are GMT -5. The time now is 12:03 AM.