How do I access the Linode-provided environment variables in a StackScript?

Linode Staff

How do I access the Linode-provided environment variables in a StackScript?

1 Reply

When running a StackScript, there are four environment variables provided by default, that are only available while the StackScript is executing. Those variables are:

LINODE_ID
LINODE_LISHUSERNAME
LINODE_RAM
LINODE_DATACENTERID

To access their values, they can be referenced like any other variable, using a command like echo or printf. For example:

echo "$LINODE_ID"
printf "%s\n" "$LINODE_LISHUSERNAME"

To save this information to a file, you can use a string of commands like the following:

echo $LINODE_ID >> /root/vars.txt
echo $LINODE_LISHUSERNAME >> /root/vars.txt
echo $LINODE_RAM >> /root/vars.txt
echo $LINODE_DATACENTERID >> /root/vars.txt

After executing those commands inside of your StackScript, you will find their values stored in /root/vars.txt. You can alter the location of the file to any place you'd like to store the data.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct