1. Manually parse parameters, position parameters(1) $#: Number of parameters(2) $1...$9: first parameter ... 9th parameter2. Built-in command parsing, getopts, long parameter format not supportedCommand format: getopts option_string variableThe
Recently wrote a small program that takes time to traverse as part of a directory#!/bin/bashfor i in {1..30}dodate= ' date +%y/%m/%d-d "$i days Ago" ' Echo $datedoneFor loop, take the date of the last n days.The core isDate= ' Date +%y/%m/%d-d ' $i
In the shell, arguments can be passed to a function when it is called. Inside the function body, the value of the parameter is obtained in the form of a $n, for example, $ $ for the first argument, and $ = for the second argument ...Examples of
ShellApplication TipsTips:1, command completion function: Key2, clear screen:ctrl+l3. Delete all contents before cursor:ctrl+u4. Command history: HistoricalThen:! History The command label listed, you can execute that command. Such as:! 188Also:
By default, Unix Commands obtain input from the standard input device (stdin) and output the result to the standard output device (stdout) for display. Generally, the standard input device is the keyboard, and the standard output device is the
The scenario where the problem occurs is probably 1 cron calls a Python script 2. In the Python script, call a shell script (for log analysis) to obtain the shell output and then send an email. Similar to a monitoring task. There is no
'.' Matches any character
'*' Specifies that * can be used repeatedly for any number of times.
'^' Starts with a string
'$' String end
'. *' Any number of characters
'\' Escape Character
'[...]' Matches any character
'[^...]'
Bash environment variables have arbitrary code execution vulnerability: "Using CGI requests can cause remote code execution, which in turn leads to server intrusion, causing serious harm,Patches officially announced are also
The terminal on Mac uses the Bourne-again shell command, bash for short.
Bash is a project developed and promoted by GNU and is an extension of the Bourne shell.
Bourne shell is the original shell used by UNIX, author Steven Bourne
Bash is the
Shell is an important tool in Unix/Linux to parse user input commands. Next we will implement a simple shell program to practiceFork/exec/Wait/exitBy the way, we recommend a book titled understanding Unix/Linux programming-A Guide to theory and
Awk
Awk is a programming language used to process text and data in Linux/Unix.
SedSed is a stream editor that is a very useful tool in text processing.
GrepGrep is a powerful text search tool, which is often used in combination with pipelines.
Simple shell script exercises
Simple Example
Conversation Script: The variable content is determined by the user.
[[Email protected] Scripts] # vi sh02.sh #! /Bin/bash # program: # user inputs his first name and last name. program
Shell obtains the gateway and modifies the IP address to enable the NIC.
#! /Bin/bash # autho freefei # script is a init computer ETH # data 2014 10 09 192.168.1.1netstats =$ (netstat-r | grep default | cut-f 10-d ''); echo $ netstats; # change
Variable
Local variable: similar to local variables, only valid for the current Shell Process
Environment variable: applicable to all sub-processes generated by login Processes
Location Parameter: used to pass parameters to shell scripts,
Arithmetic Operations
The arithmetic operations mentioned here refer to addition (+), subtraction (-), multiplication (*), Division (/), and remainder (%, you can add parentheses to change the priority and only perform operations on integers (Linux
In linux/centos shell scripts, the password is not interactively modified. In centos, the password is not modified.Today, when I wrote a shell script, I found that the user's password needs to be set and the password is set to interactive. This is
Shell upgrade,/bin/bash versions 4.1 to 4.3
Bash environment variables have arbitrary code execution vulnerability: "Using CGI requests can cause remote code execution, which in turn leads to server intrusion, causing serious harm,Patches officially
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service