Home Java javaTutorial [shell programming] syntax

[shell programming] syntax

Jun 26, 2017 am 11:20 AM
shell programming grammar

1. Declare variables

myUrl="http://see.xidian.edu.cn/cpp/linux/"
myNum=100

Note:
There cannot be a space between the variable name and the equal sign, which may be different from all programming languages ​​you are familiar with.
At the same time, the naming of variable names must follow the following rules:
The first character must be a letter (a-z, A-Z).
There can be no spaces in the middle, and underscores (_) can be used.
Punctuation marks cannot be used.
You cannot use keywords in bash (you can use the help command to view reserved keywords).

2. Use variables

echo ${your_name}
Note: It is recommended to add curly braces to all variables. This is a good programming habit.

3. Redefine variables

myUrl="http://see.xidian.edu.cn/cpp/linux/"
echo ${myUrl}
myUrl= "http://see.xidian.edu.cn/cpp/shell/"
echo ${myUrl}

Note: You cannot write $myUrl="http:// during the second assignment. see.xidian.edu.cn/cpp/shell/", only add the dollar sign ($) when using variables.

4. Read-only variables

myUrl="http://see.xidian.edu.cn/cpp/shell/"
readonly myUrl
myUrl="http: //see.xidian.edu.cn/cpp/danpianji/"

Run the script, the results are as follows:
/bin/sh: NAME: This variable is read only.

五, Delete variables
After a variable is deleted, it cannot be used again; the unset command cannot delete read-only variables.
unset variable_name

6. Variable type
When running the shell, there will be three types of variables:
1) Local variables
Local variables are defined in scripts or commands, and are only defined in scripts or commands. Valid in the current shell instance, programs started by other shells cannot access local variables.
2) Environment variables
All programs, including programs started by the shell, can access environment variables. Some programs require environment variables to ensure their normal operation. Shell scripts can also define environment variables when necessary.
3) Shell variables
Shell variables are special variables set by the shell program. Some of the shell variables are environment variables and some are local variables. These variables ensure the normal operation of the shell

The above is the detailed content of [shell programming] syntax. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Remove duplicate values ​​from PHP array using regular expressions Remove duplicate values ​​from PHP array using regular expressions Apr 26, 2024 pm 04:33 PM

How to remove duplicate values ​​from PHP array using regular expressions: Use regular expression /(.*)(.+)/i to match and replace duplicates. Iterate through the array elements and check for matches using preg_match. If it matches, skip the value; otherwise, add it to a new array with no duplicate values.

What are the syntax and structure characteristics of lambda expressions? What are the syntax and structure characteristics of lambda expressions? Apr 25, 2024 pm 01:12 PM

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

The difference between PHP functions and Shell functions The difference between PHP functions and Shell functions Apr 24, 2024 pm 06:39 PM

The main differences between PHP functions and Shell functions are security (PHP functions are more secure), reliability (Shell functions vary by operating system), functionality (Shell functions are more powerful but limited by the shell), and performance (PHP functions are usually faster) and complexity (Shell functions are more complex). They are both used for file system, process and command operations, but PHP functions are built-in, while Shell functions are called through an external shell. Therefore, in server file download scenarios, the file_put_contents() function is safer, while the wget command is more flexible.

What is programming for and what is the use of learning it? What is programming for and what is the use of learning it? Apr 28, 2024 pm 01:34 PM

1. Programming can be used to develop various software and applications, including websites, mobile applications, games, and data analysis tools. Its application fields are very wide, covering almost all industries, including scientific research, health care, finance, education, entertainment, etc. 2. Learning programming can help us improve our problem-solving skills and logical thinking skills. During programming, we need to analyze and understand problems, find solutions, and translate them into code. This way of thinking can cultivate our analytical and abstract abilities and improve our ability to solve practical problems.

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

Collection of C++ programming puzzles: stimulate thinking and improve programming skills Collection of C++ programming puzzles: stimulate thinking and improve programming skills Jun 01, 2024 pm 10:26 PM

C++ programming puzzles cover algorithm and data structure concepts such as Fibonacci sequence, factorial, Hamming distance, maximum and minimum values ​​of arrays, etc. By solving these puzzles, you can consolidate C++ knowledge and improve algorithm understanding and programming skills.

Unleash Your Inner Programmer: C for Absolute Beginners Unleash Your Inner Programmer: C for Absolute Beginners Oct 11, 2024 pm 03:50 PM

C is an ideal language for beginners to learn programming, and its advantages include efficiency, versatility, and portability. Learning C language requires: Installing a C compiler (such as MinGW or Cygwin) Understanding variables, data types, conditional statements and loop statements Writing the first program containing the main function and printf() function Practicing through practical cases (such as calculating averages) C language knowledge

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

See all articles