understanding .ksh

hi guys

we have inherited some .ksh files which we are trying to understand.

I have some questions in the below .ksh file


if [ "$#" -lt 1 ]; then   --does this mean paramatres less than 1 ?
        echo "Usage: $0 $1 <config file>"
        exit 1
fi

SCRIPT_PATH="${BASH_SOURCE[0]}";   --what is BASH_SOURCE[0]  mean here?
if([ -h "${SCRIPT_PATH}" ]) then   --what does this mean?
  while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done   --what does this mean?
fi

Open in new window


thanks
royjaydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
if [ "$#" -lt 1 ]; then

>> --does this mean paramatres less than 1 ? <<

Yes, $# contains the number of command line parameters.

 [  ] indicates a test, and -lt means "less than"

Please note that "--" does not start a comment! ksh comments start with "#"
0
woolmilkporcCommented:
All the stuff below is not ksh, it's exclusively bash-specific, unless there is a config file which is sourced at script start setting the mentioned variables.

BASH_SOURCE is an array variable containing the source names of the functions in FUNCNAME.

FUNCNAME is an array variable containing the names of all shell functions currently in the execution call stack.

[ -h "${SCRIPT_PATH}" ] tests whether the name found with  ${BASH_SOURCE[0]} exists and is a symbolic link..

while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done

replaces the link found in BASH_SOURCE with its actual filename. A while loop is actually not required, since ${SCRIPT_PATH} will just contain the first array element.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
thanks
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

royjaydAuthor Commented:
>>[ -h "${SCRIPT_PATH}" ] tests whether the name found with  ${BASH_SOURCE[0]} exists and is a symbolic link..

can you please tell me what is a symbolic link ?
0
woolmilkporcCommented:
A symbolic link is an entry in a filesystem (a special type of file) which contains a reference to another directory or file.

A symbolic link is "transparent" to most applications, which means that you can work with the link as you could with the original file. The filesystem will forward requests against the link to the original file or directory.
0
royjaydAuthor Commented:
thanks
0
royjaydAuthor Commented:
any  help will be greatly appreciated.
http://www.experts-exchange.com/OS/Linux/Q_28254996.html

thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.