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

How to learn the parameter passing of Shell

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to learn Shell parameter transfer, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Parameter transfer

The shell script can be run by passing parameters to the script as automatic input parameters

#! / bin/bash# definition array echo "Shell transfer Test"; echo "this is fruit: $0"; echo "this is fruit: $1"; echo "this is fruit: $2"

You need to import the passed values when you run the script

Chmod + x test.sh./test.sh Banana apple orange# shows that this is fruit: Banana;, this is fruit: apple;, this is fruit: orange

Special characters:

$# number of parameters passed to the script $* displays all parameters passed to the script.

The ID number of the current process that the script runs $! The last process running in the background has the same ID number $@ as $*, but uses it in quotation marks and returns each parameter in quotation marks.

For example, "$@" is only reflected in double quotes, with "$1" and "$2". Outputs all parameters in the form "$n". $- displays the current options used by Shell, which is the same as the set command. $? Displays the exit status of the last command. 0 indicates that there is no error, and any other value indicates an error. # determine whether the previous operation is successful or not, that is, whether the operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful, that is, whether the previous operation is successful or not, that is, whether the previous operation is successful, that is, whether Then echo-e "\ 033 [36mThis * fulfilled!\ 033 [0m" else echo-e "\ 033 [32mthis * failed!!\ 033 [0m" fi# determines whether a parameter is entered into if [- n "$1"] Then echo "contains the first parameter" else echo "does not include the first parameter" fi# determines whether the directory exists #! / bin/bashBAK_DIR=/usr/local/tomcat/webapps_bak/ `date +% Y% m% d`if [!-d $BAK_DIR] Then mkdir-p $BAK_DIR fi# determines whether the file exists #! / bin/bashBAK_DIR=/usr/local/tomcat/webapps_bak/ `date +% Y% m% d`if [!-e $BAK_DIR] Then touch $BAK_DIR fi# determines whether the string is the same. Note that the space uses #! / bin/bashBAK_DIR= "str" if [[${BAK_DIR} = ${BAK_DIR}]] Then echo "${BAK_DIR} same" else echo "${BAK_DIR} different" is it helpful for fi to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Servers

Wechat

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

12
Report