Referencing a Script from within a Script (2024)

You can create a script of often-used functions and re-use that script from any other scripts. You do this using the Add .NET Script Reference command.

Adding a script reference

  1. Create a single script that you want to re-use or reference from another script.
  2. Create a new driving script that will call your re-used script.
  3. Expand the Properties tab.
  4. Right click and select Add .NET Script Reference.
  5. Select the script that you want to use click OK.

Script example

The following sample contains a script file called Calculator that will be referenced from another script.

Note: Since the following has no Main() method, it cannot run on its own.

Public Class Calculator Public Shared Function Add(left As Integer, right As Integer) Return left + right End Function Public Shared Function Subtract(left As Integer, right As Integer) Return left - right End Function Public Shared Function Multiply(left As Integer, right As Integer) Return left * right End Function Public Shared Function Divide(left As Integer, right As Integer) Return left / right End FunctionEnd Class

Create another script, and add Calculator as a reference (expand the Properties tab, right click, select Add .NET Script Reference, and select Calculator) , and use the following code:

Public Module MainDim _desktop As Desktop = Agent.DesktopPublic Sub Main()MsgBox("2 + 3 = " + Calculator.Add(2, 3).ToString())End SubEnd Module
Referencing a Script from within a Script (2024)

FAQs

How do you call a script within a script? ›

Script Calling Another Script

This allows the calling script to execute the called script's commands and functions within its own environment. echo "Hello, World!" #!/bin/bash # Define a function hello() { echo "Hello, World!" } #!/bin/bash # Define a function hello() { echo "Hello, World!" }

How do I include a shell script in another script? ›

Run the Script in the Same Process

If we want a script to have access to variables and functions defined in another script, we can use the source command. The source command acts as if we copied the text from the script that was given to it as a parameter to the script in which it's called.

How do you run a script from a Bash script? ›

To run a bash script in a Unix-like operating system, you use the bash command followed by the script name with the syntax, bash example_script.sh . This command tells the system to interpret the script using the Bash shell, executing the commands within. In this example, my_script.sh is the name of your bash script.

How do you call a shell script? ›

Steps to write and execute a script
  1. Open the terminal. Go to the directory where you want to create your script.
  2. Create a file with . sh extension.
  3. Write the script in the file using an editor.
  4. Make the script executable with command chmod +x <fileName>.
  5. Run the script using ./<fileName>.

Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6135

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.