Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use an Enum defined in another script

How can I define an Enum global to use it outside of the defined scope? I created a script which imports another script (including all global functions, variables and enums)

Enum CrudFlag
{
  Undefined
  Create
  Read
  Update
  Delete
}
like image 334
Augustin Ziegler Avatar asked May 19 '26 09:05

Augustin Ziegler


1 Answers

You have to import your script using dotsourceing:

Each script runs in its own scope. The functions, variables, aliases, and drives that are created in the script exist only in the script scope. You cannot access these items or their values in the scope in which the script runs.

To run a script in a different scope, you can specify a scope, such as Global or Local, or you can dot source the script.

The dot sourcing feature lets you run a script in the current scope instead of in the script scope. When you run a script that is dot sourced, the commands in the script run as though you had typed them at the command prompt. The functions, variables, aliases, and drives that the script creates are created in the scope in which you are working. After the script runs, you can use the created items and access their values in your session.

To dot source a script, type a dot (.) and a space before the script path

Source.

like image 102
Martin Brandl Avatar answered May 21 '26 05:05

Martin Brandl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!