OTS ‐ Variables - Mistium/Origin-OS GitHub Wiki

OTS Variables Documentation

Introduction

OTS is now a full-fledged language that allows for scripts to be run through the terminal. One of the key features of any programming language is the ability to use variables. This document will guide you through the use of variables in OTS, including how to define, manipulate, and utilize them in your scripts.

Defining Variables

You can define a new variable in OTS using the = symbol. The syntax is as follows:

varname = value

Example:

greeting = hello world

In this example, the variable greeting is assigned the value hello world.

Redirecting Output to Variables

You can redirect the output of any terminal command into a variable using the >> symbol. This is useful for capturing the output of commands and storing them in variables for later use.

Example:

ls >> home

This command sets/creates the variable home with the value of the output of the ls command, which lists the contents of the current directory.

Calling Variables

You can call a variable in OTS using the $ symbol. This allows you to use the value stored in the variable in your commands or scripts.

Example:

ls >> home
echo $home

In this example, the output of the ls command is stored in the home variable, and then echo $home prints the contents of the home variable, which would produce the same output as a normal ls command.

Additional Examples

Example 1: Combining Commands and Variables

# Define a variable with a simple string
message = Hello, OTS!

# Print the message variable
echo $message

Output:

Hello, OTS!

Example 2: Storing and Using Command Output

# Capture the output of the 'pwd' command (prints the current directory) into a variable
pwd >> current_dir

# Print the current directory stored in the variable
echo $current_dir

Output:

Origin/(C) Users/Username

Example 3: Using Variables in File Operations

# List all files in the current directory and store in a variable
ls >> files

# Print the list of files stored in the variable
echo $files

Output (example):

file1.txt
file2.txt
directory1
directory2

Example 4: Combining Variables

# Define two variables
first_name = John
last_name = Doe

# Combine variables to form a full name
full_name = $first_name $last_name

# Print the full name
echo $full_name

Output:

John Doe

Conclusion

Variables in OTS provide a powerful way to store and manipulate data, making your scripts more dynamic and flexible. By using the =, >>, and $ symbols, you can easily define, capture, and utilize variables in your terminal commands and scripts. Experiment with these features to enhance your OTS scripting capabilities!