Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common parameters and functions of set command in Linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people don't understand the knowledge points of this article "What are the common parameters and functions of the set command in Linux", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and there is a certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "What are the common parameters and functions of the set command in Linux".

The set command displays shell variables that already exist on the system and sets new values for shell variables. When using set to change shell properties, the symbols "+" and "-" turn the specified mode on and off, respectively. The set command cannot define new shell variables. If you want to define a new variable, you can use the declare command to define it in the form variable name = value.

Common parameters and functions of set command

The set command without parameters is used to display environment variables.

root@3500f62fe5ae:/workspace# setBASH=/bin/bashBASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:histappend:hostcomplete:interactive_comments:progcomp:promptvars:sourcepathBASH_ALIASES=()BASH_ARGC=()BASH_ARGV=()BASH_CMDS=()BASH_LINENO=()BASH_SOURCE=()BASH_VERSINFO=([0]="4" [1]="3" [2]="48" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")BASH_VERSION='4.3.48(1)-release'COLUMNS=236CUDA_HOME=/usr/local/cudaCUDA_PKG_VERSION=10-0=10.0.130-1CUDA_VERSION=10.0.130CUDNN_VERSION=7.6.0.64... set -e

The-e parameter means that whenever an error occurs in the shell script, i.e., the command return value is not equal to 0, execution stops and the shell exits. set -e is often used in shell scripts. By default, shell scripts report errors when they encounter them, but continue to execute subsequent commands.

The test.sh script reads:

#!/ usr/bin/env bashset -ehelloecho "Hello set"

The results are as follows:

root@3500f62fe5ae:/workspace# sh test.shtest.sh: 4: test.sh: hello: not found

Note: set +e means to close the-e option, set -e means to reopen the-e option.

set -u

The-u parameter indicates that shell script execution will report an error and stop if it encounters a variable that does not exist. By default, without the-u argument, shell scripts will not report errors when they encounter variables that do not exist, and will continue to execute.

The test.sh script reads:

#!/ usr/bin/env bashecho $testset -uecho $hello

The results are as follows:

root@3500f62fe5ae:/workspace# sh test.shtest.sh: 5: test.sh: hello: parameter not set The above is about "What are the common parameters and functions of the set command in Linux" The content of this article, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report