http://tldp.org/LDP/abs/html/Advanced Bash Scripting Programming GuideAn in-depth exploration of scripting language artThis tutorial does not assume previous scripting or programming knowledge, but progresses quickly toward an intermediate/advanced level of instruction ... h
Daniel RobbinsPresident and CEO, Gentoo Technologies, Inc.March 2000
By learning how to program using the bash scripting language, you can make the daily interaction of Linux more interesting and productive. You can also use the familiar and favorite standard UNIX concepts (such as pipelines and redirection ). In this three-part series, Daniel Robbins provides an example of how to program using
Little exercise: Write a scriptDetermine if a user's default shell is bash on the systemIf there is one, it shows how many such users will otherwise show no such user#!/bin/bash#grep "bash$"/etc/passwd >/devnullCode=$?If [$CODE-eq 0]; Thenusernu= ' grep ' bash$ '/etc/passwd
), in order to better portability, it is recommended to use the second way of writing.
Include a file and execute a file, as well as write the path to the file, not to write the filename, such as the above example:
. ./function.sh
Can not write:
. function.sh
If function.sh is a user-passed parameter, how do you get its absolute path? The method is:
real_path = `readlink -f $ 1` # $ 1 is a parameter entered by the user, such as function.sh
. $ real_p
hypothetical shell
In the references section, you can find some links to learn about the Open Source Bash shell architecture.
Explore Linux shell
Now let's look at some of the shells, review their contributions and view the sample scripts in each shell. You can view C
, form.html
(2) Write a request to receive the CGI, the above action has been specified, that is, form_test.sh
#!/bin/bash
echo ' content-type:test/html ' echo ' echo
$QUERY _string
2 implement a return HTML page with the title and content of Hello worldThe page effect returned is as follows:
The implementation method, also implements a CGI, just returns the content is an HTML:
#!/bin/bash echo '
Bash (GNU Bourne-again Shell) is a Unix shell written for the GNU program, which is the default shell used by many Linux platforms.Variables for bash scripting:1. $BASHRepresents the path of a
At the beginning of the new year, the knowledge base of open source class is online. Early on, the Linux command Encyclopedia/bash Reference, Advanced Bash Scripting Programming Guide, is available in two series. Other materials are on the line.Among them, the Advanced Bash Scrip
https://www.zhihu.com/question/21418449Mort | Zsh vs. Bash: Incomplete contrast resolution (1) 2014-10-07BdpqlxzWhat's the difference between zsh and bash?A lot of people have written about "why zsh is better than bash", "Why zsh is better than Shell", the tutorial on how to
files under/var/logPut all the commands in one file and build up the script, here is the simplest command to stack up the script, empty the log script.Cd /var/logCat /dev/null > messagesEcho “Logs cleaned up.”Expand: Three ways to empty logs and file contents[[emailprotected] ~]# echo >test.log [[emailprotected] ~]# >test.log [[emailprotected] ~]# cat /dev/null >test.logScenario: Preserve files and empty content.Two Shell language and category Introd
Advanced Bash-scripting Guide (15th): Test broken link files (broken link ),
The example selected in this article is from the book "Advanced Bash-scripting Gudie", translated by Yang chunmin Huang Yi
1 #/bin/bash 2 # use a pure shell
code.
8. Avoid weaknesses
Sometimes, using a shell to write a script means that it is difficult to migrate, make it difficult to handle errors uniformly, and handle data easily.Although the use of external commands can quickly and easily achieve a variety of complex functions, but as the reverse side of the coin, you have to rely on grep, SED, awk and other tools to glue them together.
If you have multiple platform-compatible requirements, be care
Scripting of Bash functions under Linux (11)1. Function of script programming:Function: Structured programming, cannot run independently, needs to be executed when called, can be invoked multiple timesFormat 1:Function name {Statement...}Format 2:Function name () {Statement...}2. Call function Execution status return value:Format: return value, value between 0-2553. Use the function to complete the script t
Shell Scripting Learning GuideThe following eight points can not be said to be your shell Scripting Learning Guide de all, at least let you write a reliable shell script.1. Specify bashThe first line of the shell script, what shou
, and the shell interprets the execution.• Batch processing (Batch): The user writes a shell script in advance, with many commands that allow the shell to execute the commands one at a time without having to hit the command one by one.
Shell scripts and programming languages are similar, there are variables and proces
Bash concise tutorial -- variables, bash concise tutorial Variables
1. Preface
Bash is a popular scripting language in * nix systems. As a scripting language, variables are the basic el
field (unit testing, single-step debugging, IDE, Third-party class libraries).
The new learning cost is minimal, as long as you learn how to use the Shell interpreter (Jshell, adascript).
Simple vs Advanced
If you feel familiar with the language (such as Java, C) writing shell scripts is too verbose, you just want to do some backup files, install software, download data and other thin
what's the feature of this bash?1) Record command historyThe commands we've knocked on, Linux will be recorded, and presets can record 1000 historical commands. These commands are saved in the. bash_history file in the user's home directory. One thing you need to know is that commands that run in the current shell are saved to the. bash_history file only when the user exits the current
shell. One of the most interesting features of the Korn shell is that it is not only backward compatible with the original Bourne shell, but can also be used as a scripting language.
In 2000, Korn shell was released in open source form (based on the Common Public License) a
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.