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

Descriptions of some common environment and parameter variables in shell scripts and examples of simple shell scripts

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this issue, the editor will bring you an explanation of some common environment variables and parameter variables in shell scripts, as well as simple shell script examples. the article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Environment variable

$HOME

Current user's home directory

$PATH

A colon-separated list of directories used to search for commands

$PS1

The command prompt is usually the $character, but in bash, you can use some more complex values. For example, the string [\ u@\ h\ w] $is a popular default value, which gives the user name / machine name and the current directory name, as well as a $prompt.

$PS2

A secondary prompt, which is used to indicate subsequent input, usually the > character.

$IFS

Enter a domain delimiter. When shell reads input, it gives a set of characters used to separate words, usually spaces, tabs, and newline characters.

, 0

The name of the shell script

$#

The number of parameters passed to the script

$

The process number of the shell script, which the script usually uses to generate a unique temporary file, such as / temp/tmpfile_$$

Parameter variable

$1, $2.

Parameters of the script

$*

All the parameters are listed in a variable, separated by the first character in the environment variable IFS. If the IFS is modified, the way $* separates the command line into arguments will change.

$@

It's an ingenious variant of $* that doesn't use the IFS environment variable, so even if IFS is empty, the parameters don't squeeze together.

Sample shell script #! / bin/shsalutation= "Hello" echo $salutationset foo bar bamecho "The program $0 is now running" echo "The second parameter was $2" echo "The first parameter was $1" echo "The parameter list was $*" echo "The user's home directory is $HOME" echo "Please enter a new greeting" read salutationecho $salutationecho "The script is complete" exit 0 test results

This script creates the variable and displays its contents, and then shows that the various parameter variables and the environment variable $HOME already exist and have the appropriate values.

The above is the description of some commonly used environment variables and parameter variables in the shell script program shared by Xiaobian, as well as simple shell script examples. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, 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.

Share To

Development

Wechat

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

12
Report