Bash script exercises and bash scripts
Exercise 1:
1. Add five users, user1,..., user5;
2. The password of each user is the same as the user name. After the password is added, the command execution result is not displayed;
3. After each user is added, it must be displayed that the user has been added successfully.
Useradd user1
Echo "user1" | passwd -- stdin user1 >/dev/null
Echo "User1 added ."
C
Bash metacharacters (upper) and bash characters
Metacharacters
Function
Example
Carriage return line feed
End a command
Space
Split elements in a command line
Ls/etc
Tab
Command auto-completion
#
Start a line of comment
# This is a comment line
"
Multiple characters referenced but allowed to be replaced
"$ File". ba
Bash internal variable, Bash variable
Bash internal variables
Some internal commands are invisible in the directory list. They are provided by the Shell itself. Common internal Commands include echo, eval, execexport, readonly, read, shift, wait, exit and point (.)
Echo variable table
Display the specified variable in the variable table to the standard output.
Ev
Bash remote code execution vulnerabilities are really much more powerful than heart drops, but the impact is not very broad, but yesterday's analysis of the article bash The Remote Code execution vulnerability analysis at the end of this paper mentions the bulk problem of the vulnerability.
One of the easiest ways to do this is to use the search engine's hacking technology, where I use the Google hacking sy
************************************************************************* * * * Original:blog.csdn.net/clark_xu Xu Changliang's Column************************************************************************? time to read the file#!/bin/bashFor file in ' Ls/root 'DoStat $file >1.txtSed-n "7p" 1.txt>2.txtUsetime= awk-f ":" ' {print $2.txt} 'echo "Time=" $file $usetimeDone? reads each line of the file while statement. Cat Afile | While Read onelineDoEcho $onelineDone? reads each line of the file
Wildcard characters in Bash (wildcard)*: Any character of any length.?: any single character []: Match range [^]: Exclude Match range [: alnum:] [: Alpha:] [: Blank:] [: cntrl:][:d Igit:] [: Graph:] [: Lower:] [:p rint:][ :p UNCT:] [: Space:] [: Upper:] [: xdigit:]Regular expressions.: Indicates matching any single character. *: Indicates that matches the preceding character any time, including 0 times. *: represents any character that matches any len
Learning bash notes-debugging shell programs and learning bash shell
In shell, the simplest debugging assistant outputs the echo statement. Many echo statements can be put into the code for debugging, but it takes enough time to locate
The information to view. You may need to output a lot to find the information you want to search.1. the most basic set-o Command Options are set-o Command Options. These opti
Location parameters$0, $1, $2, etc. .. (note that when the number of parameters is greater than 9, you should reference $ {10}, ${11 }...)Location parameter, which is passed to the script from the command line, to the function, or to a variable.Example:
#! /Bin/bash
#./Test. Sh first second third
Output:
First parameter first
$0 =./test. Sh
When the number of parameters is greater than 9:
#! /Bin/bash
#./
commands,Hisfilesize defines the maximum history file size,The Histcontrol definition ignores leading spaces,Histingore defines a command that does not need to be stored, where ignoredups ignores duplicate rows, Ignorespace ignores lines with leading spaces, Ignoreboth ignores bothHistfile Defining History filesShell all parameters $* [email protected] the latter is separate, remember to use double quotation marks, otherwise read into the parameters are still separated by a space to pass to the
Telnet is unavailable !!! Tip:-bash: telnet: command not found, telnet-bashI. Check1. [root @ localhost ~] # TelnetBash: telnet: command not found2. Check whether the Telnet package is installed. The result is as follows:[Root @ localhost ~] # Rpm-qa telnet *Telnet-server-0.17-47.el6.i6863. query the xinetd status again:[Root @ localhost ~] # Service xinetd statusXinetd (pid 2967) is running...4. Run the ntsysv command to enable the Telnet service. Yo
I am a new Linux user. Now I need to clean up a download directory of files, in fact, I just want to delete from the ~/download/folder except for files in the following format, other files:
1.*.iso-all ISO format files.2.*.zip-Files in all zip formats.
How do I remove a specific file from a bash shell on a linux,os X or unix-like system?
The Bash shell supports rich file pattern matching characters such as
I am a new Linux user. Now I need to clean up a download directory of files, in fact, I just want to delete from the ~/download/folder in addition to the following format files so other files:
1.*.iso-All documents in ISO format.2.*.zip-All files in zip format.
How do I delete a particular file in a bash shell based on a linux,os X or unix-like system?
The Bash shell supports rich file pattern matching c
= ' egrep--color=auto ' 2>/dev/null/etc/profile.d/colorgrep.sh:7:alias fgrep= ' fgrep--color=auto ' 2>/dev/null/etc/profile.d/which2.csh:5:# alias which ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '/etc/profile.d/which2.sh:4:alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '=================================part2Built-in Commands bash built-in commandsMany kinds ofFirst: Bash's own features see
Why can't we find the command bash: Is: the command-Linux general technology-Linux technology and application information Is not found. The following Is a detailed description. Example
To install the software today, first download a tz package and check how to install it online. The result Is half installed. When the make command Is used, the file does not exist and then the Is command Is used, the result is as follows:
Jun @ jun-laptop :~ $ Is
, so that you can get a set of numbers from large to small in reverse order, such as: {100..1} is all integers that count from 100 to 1. Whether it is x or Y, as long as it represents a decimal, it can be "0". The default "INCR" is "1" or "1".The curly brace expansion is done before any other expansion, and any characters that have special meaning to the other expansion remain in the result. It is carried out strictly literally. Bash does not make any
(kw:process Substitution)> (cmd list)7. Path name expansion (Kw:pathname Expansion)*, ?, []Expand, expand, not unfold, and remain intact.6. Redirection (1.5), (kw:redirection)Before a command executes, its inputs and outputs may be redirected by the shell, and the redirection operation has the following functions:redirect Input (kw:redirecting input, here Documents, here Strings)Wc-l CMD ..EofCMD Redirected outputs (kw:redirecting output)Copy file descriptor (kw:duplicating descriptors)EXEC 4>3
The following two tips to enhance Bash functions: one is to improve Bash command history management, and the other is to enable Bash to have a more intelligent automatic completion feature. The implementation process is not complex. You only need to modify the default configuration of Bash. Improve
Linux bash script concise manual! Script Execution and debugging 1. absolute path execution. The file must have the execution permission. 2. Execute the sh command without the execution permission. 3 ,. add space or source to execute the command. The script will be executed in the current shell. 4. Check the script syntax bash-v test. sh5. Execute bash-x test. sh
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.