Solved

Execute ksh in current environment without dot

Posted on 2014-04-04
3
228 Views
Last Modified: 2014-04-04
Hi,
I need to find the way to execute scripts from main script in current environment, but not use "." (dot)  before script name
Example

#!/usr/bin/ksh
.  ~/script1
.  ~/script2

Maybe use some flag in ksh, etc...

Thanks in advance
0
Comment
Question by:IKeystone
  • 2
3 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39978350
Why not just

~/script1
~/script2

Where's the problem? Do you have to give back environment variables to the main script? That's the only reason for the dot I could imagine.

Of course you have to "export" variables which must be known by the called scripts.

And finally, what's wrong with the dot? Why don't you want to use it?


wmp
0
 

Author Comment

by:IKeystone
ID: 39978449
It is interactive tool I wrote. Variables going back and forward from script to script but stay inside actual session. I need to encrypt scripts but encryption tool  doesn't like dot. In tcsh it is easier (source instead dot) but I don't want to re-write all.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39978465
So why not "export" the variables which must be made available to called scripts?  ksh does this automatically when invoked with the "-a" flag.

To make variables set in a called script available to the calling script there is no other way than using the dot or "source", if you don't want to use an external config file.

"bash" allows using "source" instead of the dot and is widely compatible with ksh. Could  bash be an option?

Another idea: Export a variable called SOURCE in the main script:

export SOURCE="command . "

and use $SOURCE instead of the dot, like:

$SOURCE ~/script1
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question