In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use the Linux readonly command, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this Linux readonly command article. Let's take a look at it.
The Linux common command readonly command is used to define read-only shell variables and shell functions. The option-p of the readonly command outputs and displays all read-only variables defined in the system.
Readonly marks a shell variable or function as read-only
Syntax readonly [- aAf] [name [= value]...] The main purpose of readonly-p is to define one or more variables and set read-only properties.
Sets read-only properties for one or more variables that have been defined.
Displays all variables that contain read-only properties.
Sets read-only properties for one or more functions that have been defined.
Displays all functions that contain read-only properties.
Option-a: point to the array. -A: points to the associative array. -f: points to the function. -p: displays all read-only variables. The option after it is not valid. Parameter name (optional): variable name or function name value (optional): the value of the variable returns the value readonly returns true unless you provide an illegal option or illegal name.
Example # define variables and add read-only attributes readonly var1=13 var2 readonly-an arr1= (12345) arr2= ('z'x''c') # must have'- A 'option readonly-A dict1= ([' key1'] = 'value1') # define variables and functions first Then add read-only attribute max=3 readonly max # array definition without `read-a` seasons= ('spring'' summer' 'autumn'' winter') # add read-only attribute without `- a` option readonly seasons declare-A man= (['age'] = 23 [' height'] = '190cm') # add read-only attribute to associative array without`-A` option readonly man function foo () {echo' bar' } # when you add a read-only attribute to a function, you must add the `- f` option readonly-f foo # to display all read-only variables. The following two commands display the same result as readonly readonly-p # shows an array of all read-only attributes readonly-a # shows an associative array of all read-only attributes readonly-A # shows all functions with read-only attributes common errors for read-only variables If the user modifies its value, an error will be reported immediately. For example, use this directive to define a read-only variable "test" and initialize its value to "ok", enter the following command:
[root@localhost ~] # readonly test='ok' # defines a read-only variable and initializes it so that an error will be reported when the user modifies the read-only variable directly, as shown below:
[root@localhost ~] # test='my' # attempts to modify the value of a read-only variable-bash: test: readonly variable when a user tries to modify the value of a read-only variable, the variable is prompted to be read-only.
Note that this command is a bash built-in command. For help, please see the help command.
Declare + r cannot remove read-only attributes, and unset cannot delete read-only variables.
This is the end of the article on "how to use the Linux readonly command". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use Linux readonly commands". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.