Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

K shell script?

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
US
Anyone know how to call a korn shell script from within bourne?
 
Just like you would call any program or script.

myscript

or if you want to capture the output.

OUTPUT=`myscript`
 
you can make a script run under a specific shell with what's called the (and I'm not kidding) "hash-bang" line

you see lines like this at the top of scripts

#!/bin/sh

and

#!/usr/bin/ksh

when the shell tries to execute a script, it looks for that as the first line, if it finds it - it will feed the script to that program

so to make sure a script is interpreted by the korn shell you need to put #! and the path to ksh as the first line Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Hi,

Ok Mike but to be syntactically correct the first line should be: #! /bin/ksh (or whatever shell)

notice the space between the exclamation and the forward slash. Some older OS's cannot interpret the first line without that blank space and the script will default to the current shell.

additionally, you could explicitly make the call from the calling script, with the shell type preceding the command:

i.e.

#! /bin/sh

parent script.......
commands.....
calling sub-shell..
/bin/ksh myscript
returning from sub-shell
more processing

exit 0

If you call it this way, then you don't need a 'hash-bang' in 'myscript'
 
what - really? I thought the lack of a space was required? Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top