In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
View system variables:
1.env command
[root@localhost ~]# env
2. Set command
[root@localhost ~]# set
*set can display user-defined variables
Custom variables:
1. Definition of variables:
[root@localhost ~]# a=test[root@localhost ~]# echo $atest
2. Variable naming rules: can contain upper and lower case letters, numbers, underscores (cannot start with numbers)
[root@localhost ~]# a=1[root@localhost ~]# echo $a1[root@localhost ~]# a_1=2[root@localhost ~]# echo $a_12[root@localhost ~]# a1=3[root @ localhost ~]# echo $a13[root@localhost ~]# 1a=4-bash: 1a=4: Command not found
3. Single quotes are required when variable values contain special characters ($ / \ #spaces, etc.):
[root@localhost ~]# a=abc[root@localhost ~]# echo $aabc[root@localhost ~]# a='a b c'[root@localhost ~]# echo $aa b c[root@localhost ~]# a=a b c-bash: b: no command found
4. Accumulation of variables: when the variable value contains the variable name, double quotes are required to read the variable value, and the variable name is recognized as a string with single quotes.
[root@localhost ~]# a=1[root@localhost ~]# b=2[root@localhost ~]# echo $a$b12[root@localhost ~]# c='$a$b'[root@localhost ~]# echo $c$a$b[root@localhost ~]# c="$a$b"[root@localhost ~]# echo $c12
5. Global variables: variables defined in the current shell (terminal) only take effect in the current shell (terminal), using global variables can make variables also take effect in the child shell of the current shell, but global variables defined in the child shell will not take effect in the parent shell (global variables can only take effect in the current shell and the child shell of the current shell)
Define global variables Command: export
[root@localhost ~]# a=test[root@localhost ~]# echo $atest[root@localhost ~]# bash[root@localhost ~]# echo $a[root@localhost ~]# exitexit[root@localhost ~]# export a=test[root@localhost ~]# bash[root@localhost ~]# echo $atest
6. Delete variable: unset variable name
[root@localhost ~]# a=1[root@localhost ~]# echo $a1[root@localhost ~]# unset a
Environmental variables:
1. Variable configuration file:
a. System level: /etc/profile,/etc/bashrc
b. User level: ~/.bash_profile,\~/.bashrc,\~/.bash_history,\~/.bash_logout
* System-level profiles are usually loaded at login time, user-level profiles only work for a single user
PS1 variable: indicates the content at the beginning of each line ([root@localhost ~]#)
[root@localhost ~]# echo $PS1[\u@\h \W]\$
*u for user, h for hostname, W for current directory
Change upper case W to lower case W to display absolute path:
[root@localhost ~]#cd /etc/sysconfig/[root@localhost sysconfig]#PS1='[\u@\h \w]\$'[root@localhost /etc/sysconfig]#
PS2 variable: (used in another mode, such as after logging into mysql)
[root@localhost ~]#echo $PS2>
cut command:
-d parameter: Specify division symbol, -f parameter: Specify number of segments, -c parameter: Specify number of characters
[root@localhost ~]#cat 1.txtroot:x:0:0:root:/root:/bin/bash[root@localhost ~]#cat 1.txt |cut -d ":" -f 1root[root@localhost ~]#cat 1.txt |cut -d ":" -f 1,2root:x[root@localhost ~]#cat 1.txt |cut -d ":" -f 1-5root:x:0:0:root[root@localhost ~]#cat 1.txt |cut -c 4t
sort command: sort the contents of each line from ASCII to large
[root@localhost ~]#[root@localhost ~]#cat 1.txt abcaa_1aabbop#test
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.