Skip to content

Variables

Alex Gowers edited this page Mar 1, 2021 · 1 revision

Variables

You can set variables in Lucifer through the set command, it requires two positional arguments: <variableName> and <variableValue> . When the variable is set modules that are running can access then and interact with them (Reading and Writing). In the GUI of lucifer you can see these variables update in the bottom of the right panel. These variables can also be used in commands in placeholder form as such below.

Placeholders

First set the placeholding variables through the set command or a module. Such as set ip 127.0.0.1

Now you can use the variable in commands such as set ip $ip$:4040 . When ran this translates to set ip 127.0.0.1:4040 which then set the variable ip to 127.0.0.1:4040.

When you use a placeholder and the variables can not be found, the placeholder does not get placed as such set ip $unknownVariable$ which translates to set ip $unknownVariable$.

If you want to escape the placeholder symbol ($) in a command you can use a \ as such set ip \$ip\$ which tells lucifer not to use placeholder. This translates to set ip $ip$

Finally if you variable contains the placeholder symbol ($) you can still use it in a place holder as such: set person\$name Bob (set person$name Bob) then you can use this new variables as such set person\$name $person\$name$ Jefferson this translates to set person$name Bob Jefferson.

Module access

Each shell has its own store of variables, to get access to these variables in your custom module class you can access then with the following:

self.shell.vars  # This contains the dictionary with the current shell variables

variableValue = self.shell.vars.get("CustomVariable")  # This will fetch the data in the variable: "CustomVariable"

self.shell.vars["settingAVariable"] = "MyNewVariableValue"  # This sets the variable "settingAVariable" to "MyNewVariableValue"

self.shell.vars.keys()  # Gets a list of variables

variableValue = None	# This below if the recommended way of fetching variable data to prevent key errors
if "MyVariable" in self.shell.vars.keys():
    variableValue = self.shell.vars.get("MyVariable")

I would avoid using non string types within variables.

Clone this wiki locally