In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about what the shell variables and operators in Linux refer to. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
-Local variables-commands that affect variables
-Environment variable-quotation marks
-variable substitution-operator
-position variable-expression replacement
-Standard shell variable-precedence of the operator
-Special variables
-variable:
-what is the shell variable?
-Local variable
-Environmental variables
-variable substitution (display variables)
-position variable
-Standard variable
-Special variables
-commands that affect variables
-Local variables:
-Local variables are used in the script of the user's current shell life cycle
-variable-name=value
-set displays all local variables
-readonly variable-name
# LOCALTEST= "test"
# echo ${LOCALTEST}
Test
# echo $LOCALTEST
Test
# set views variables through set
# check whether the LOCALTEST variable still exists after exit exits
# readonly LOCALTEST
# LOCALTEST= "test"
# readonly to see which read-only variables are available in the current shell
# readonly-p
-Environmental variables
-Environment variables are used for all user processes (often called child processes). The login process is called the parent process. The user processes executed in the shell are called child processes. Unlike local variables (used only in today's shell), environment variables can be used for all child processes, including editors, scripts, and applications.
-$HOME/.bash_profile (/ etc/profile)
-export
-env
# cat / etc/profile
# export Antiy= "xi'an"
# env then look for the variable Antiy
# export can also be viewed
# readonly Antiy is set to read-only
# export Antiy= "xidian" to see if it can be modified, it will prompt no, because it is read-only.
-variable substitution:
-replace its name with the value of the variable.
-echo
-add $before the variable name, and use the echo command to display the value of a single variable.
# testvar= "this is a test"
# echo $testvar
This is a test
# echo ${testvar}
Variable replacement-continued
${Variable name} displays the actual value to variable name
${Variable name:+value} if variable name is set, its value value is displayed, otherwise, it is empty!
${Variable name:?value} if variable name is not set, displays the user-defined error message value!
${Variable name:-value} if variable name is not set, its value value is displayed
${Variable name:=value} if variable name is not set, set its value and display
# echo ${testvar:+ "xidian"}
Xidian
# echo ${testvar1:+ "xidian"}
Empty
# echo ${testvar1:? "no defined"}
Bash:testvar1:no defined
# echo ${testvar1:- "xidian"}
# echo ${testvar:- "xidian"}
Xidian
# echo ${testvar:= "xidian"}
This is a test
# echo ${testvar2:= "xidain"}
Xidian
# echo $testvar2
Xidian
-variable clearing:
# echo $testvar
This is a test
# unset testvar
# echo $testvar
Vbl.
# echo $testvar2
# readonly testvar2
# unset testvar2
-location variable:
-the position variable represents $0, "1, 1, 2, and... $9."
-use position parameters in the script
-pass parameters to system commands
Example01:
#! / bin/bash
# parm01
Echo "this is the name of the script: $0"
Echo "this is the first position parameter of the script: $1"
Echo "this is the first position parameter of the script: $2"
Echo "this is the first position parameter of the script: $3"
Echo "this is the first position parameter of the script: $4"
Echo "this is the first position parameter of the script: $5"
Echo "this is the first position parameter of the script: $6"
Echo "this is the first location parameter of the script: $7"
Echo "this is the first position parameter of the script: $8"
Echo "this is the first position parameter of the script: $9"
Example02:
#! / bin/bash
# parm02
Find / home/shell/-name $1-print
-Standard variable:
-bash establishes some standard environment variables by default, which can be defined in / etc/profile.
-EXINIT
-HOME
-IFS
Echo $IFS
IFS=':'
-LOGNAME
-MAILCHECK
-MAILPATH
-TERM
-PATH
-TZ
-PS1
# set | grep "PS"
PS1=' [\ u@\ h\ w]\ $'
PS2=' >'
-PS2
-PWD
-SHELL
-MANPATH
-TERMINFO
-Special variables:
-$#: the number of parameters passed to the script
-$*: displays all parameters passed to the script in a single string. Unlike location variables, this option can have more than 9 parameters.
-$$: the ID number of the current process in which the script runs
-$!: the ID number of a process running in the background
-$@: same as $*, but use it in quotation marks and return each parameter in quotation marks
-$-: displays the current options used by shell, with the same function as the set command
-$?: displays the exit status of the * command. 0 indicates no error, and any other value indicates an error.
#! / bin/bash
# parm01
Echo "this is the name of the script: $0"
Echo "this is the first position parameter of the script: $1"
Echo "this is the first position parameter of the script: $2"
Echo "this is the first position parameter of the script: $3"
Echo "this is the first position parameter of the script: $4"
Echo "this is the first position parameter of the script: $5"
Echo "this is the first position parameter of the script: $6"
Echo "this is the first location parameter of the script: $7"
Echo "this is the first position parameter of the script: $8"
Echo "this is the first position parameter of the script: $9"
Echo "display number of parameters: $#"
Echo "Show all parameters of the script: $*"
Echo "Show process ID:$$"
Echo "shows the status of the previous command after running: $?"
Commands that affect variables:
-declare
-export
-readonly
-set
-shift
-typeset
-unset
Quotation marks, double quotes, single quotes, backquotes, backslashes
Operator, operator type
This is what the shell variables and operators in Linux refer to. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.