A detail about the code format written by shell scripts
Source: Internet
Author: User
For details about the code format of shell script writing, the format of shell script writing is not very clear. today, I wrote a script to practice writing and found some problems, as follows: the input variable YES_OR_NO is defined. according to the rule defined by the script, when the value is equal to yes, the output... A detail about the code format written by shell scripts
As a beginner in shell script writing, the format is not very clear. today I wrote a script to practice writing and found some problems, as shown below:
An input variable YES_OR_NO is defined,
According to the rule defined by the script, if the value is yes, the output is,
You input: yes
U r a sea man! Welcome you!
If the value is no, the value is
You input no
U r not a sea man, please exit this system
However, after the script is compiled, grant the executable permission to the script and compile it.
Enter the result "yes" after execution.
The screen output result is as follows:
If no expected result is obtained, an error is returned in row 4th. Considering the possible format of the condition, separate the variables before and after the condition with a space as follows:
After compilation and execution
Yes
Enter no to test
The returned value is the value of yes.
Finally, change the condition format:
Input no. the output result is:
Input yes, and the output result is
Done!
This example shows that the spacing between various variables, constants, and descriptions, and the overall format of the shell script are sometimes very exquisite. if you do not pay attention to it, it may affect the running of the program, this causes unnecessary error correction overhead.
All the codes in the following example are similar. sorry!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.