Forrest logo
back to the local tool

local:tldr:3d374

local: Declare a readonly variable with the specified value.
$ local -r ${variable}="${value}"
try on your machine

This command sets a local variable with a read-only attribute in a shell script. Here's how it works:

  • local is a shell built-in command that is used to declare local variables within a function or a block of code. It ensures that the variable is only accessible within that particular scope.
  • -r is an option for the local command, which declares the variable as read-only. Once a variable is set as read-only, its value cannot be modified or reassigned.
  • ${variable} is a placeholder that should be replaced with the name you want to give to the variable. It can be any valid variable name.
  • "${value}" is a placeholder that should be replaced with the value you want to assign to the variable. It can be any valid value, such as a string, number, or another variable.

Putting it all together, the command local -r ${variable}="${value}" declares a local variable named ${variable} and sets its value to ${value}. This variable is then made read-only, so its value cannot be changed later in the script.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the local tool