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.
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
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!" }
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.
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.
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.
We notice you're using an ad blocker
Without advertising income, we can't keep making this site awesome for you.