SHELL programmingDirectory:1.shell Brief Introduction2.shell Programming Preparation3.shell Programming Structured Language Building4. OtherTwo examples of 5.shell programmingWrite in front:1.Hello World#! /bin/bash# This is aexample of bash helloworld# you can start Shell programm
2 3
Calculate how much from 1 to N, n is the parameter you bring in when you execute the script?
VI for3.sh#!/bin/bashfor for I in ' seq $ ' do let sum+= $idoneecho "sum= $sum" execution: #bash for3.sh 100sum=5050
5 Seconds Countdown
Daojishi.sh#!/bin/bashn=5for i in ' seq 5 ' do echo ' countdown: $n ' Let n--sleep 1done execution: #bash daojishi.sh countdown: 5 Countdown: 4 Cou
As a result of the work, several bash scripts were written in the previous months, primarily for automated testing, packaging, installation packages, and so on. Although compared to C + + programming, to be simple, stupid, but it in the Unix-like system can greatly improve the efficiency of the work. So here's a brief summary of some of the considerations in scripting. 1. Shell Overview The shell is an inte
A detailed description of the variables of Bash programming under Linux (i)1. Language classification:1.1. Static language: Compiled languageStrongly typed: Variables must be declared beforehand and even initialized before they are used;Programs written in advance into executable formatRepresentatives are: C, C + +, JAVA, C #Dynamic language: Interpreted languageWeak type: variable time declaration, even th
Labels: Bash basics and standard I/O pipeline shell programming Basics
1. Bash basics and configurations
From the user's perspective, the shell type:
Logon Shell
Log On Through a terminal normally
Su-Username
Su-l Username
Non-Logon Shell
Su Username
Virtual terminal opened under the graphic Terminal
Automatically executed shell script
Bash Script Programming:If statement, Bash-n, Bash-xCONDITION:Bash command:The execution status result of the command;Success: TrueFailure: flaseThe meaning of success or failure: Depending on the command used;Single branch:if CONDITION; ThenIf-trueFiDual Branch:if CONDITION; ThenIf-trueElseIf-falseFiMulti-branch:if CONDITION1; ThenIf-trueElif CONDITION2; ThenIf-
;Environment variables:Variable assignment:(1) Export Name=value(2) Name=valueExport name(3) Declare-x Name=value(4) Name=valueDeclare-x NameVariable reference: ${name}, $nameNote: Bash has many environment variables embedded in it (usually all uppercase characters) to define the work environment for bashPATH, Histfile, Histsize, Histfilesize, Histcontrol, SHELL, HOME, UID, PWD, oldpwdView environment variables: Export, Declare-x, PRINTENV, envUndo en
'] ' + echo CCCompare the next 5-6 lines can be found, the difference is to judge once, or judge two times4.2 String Judgments#!/bin/bash-xstr1= "ABC" If [-Z "$str 1"]; Then Echo ' str1 was empty ' else echo ' str1 is not empty ' fiprintf "\ n" str2= "" if [-N "$str 2"]; then Echo ' str2 I s not empty ' else echo ' str2 is empty ' fiprintf ' \ n ' If ["$str 1" = "$str 2"]; then echo ' str1 = str2 ' Else Echo ' str1 Note:-N is-not empty to deter
Location and special variables for bash programming under Linux (iv)1.bash Position Variable:$, $, ... The 1th parameter, the second argument, ...Shift poll substitution, cullingExample: Using a script to interpret the meaning of positional variables, create the following script:Nano shift.sh Create a script file and add the following:#!/bin/
Can I do about It?Matters ComputationalType Theory and functional programmingGetting started with Open source development (PDF)Database Fundamentals (PDF)Clever algorithmsSummary of the GoF Design PatternsFlow based programmingAlgorithms and Data-structures (PDF)Compiler Construction (PDF)Project Oberon (PDF)The Little Book of semaphoresEssential Skills for Agile developmentI Am a BugMining of Massive DatasetsData-intensive Text processing with MapRe
Linux under Bash programming character test with For Loop statement (v)1. Character test:= =: Test for equality, equality is true, not equal to False! =: Test Whether it is unequal, not equal to true, etc as false>,-N String: Tests whether the specified string is empty, empty is true, or false-Z String: Tests whether the specified string is not empty, is not empty, and the null is False2.for loop: Enter con
BASH Programming Conditional judgment: Determine whether the prerequisites for subsequent operations are satisfiedCommon Types of Judgments:Integer judgment:Character Judgment:File judgment:$?: Status return value0: True1-255: FakeWe can use the status return value as the judging condition, do not need to add ' 'Boolean value:True and FalseLogical operation:and Operation:Or Operation: | |Non-op:!The conditi
Bash Programming Essentialsvariables :Local variable: Valid only for the current shell process, not valid for other shells other than the current shell (including its parent, child, etc.);Environment variables: Valid for Shell processes and their child shell processes;Local variables: Valid only within a certain piece of code space in the current shell process, usually for function local programs;Positional
Linux under Bash programming combination test and write comprehensive script (v)1.Bash Programming Combination test conditions-A: With relation-O: or relationship!: Non-relationalPresentation Method 1:[$#-gt 100-a $#-le 500]Presentation method 2:[$#-gt] [$#-le 500]2. Write a script that adds and deletes users as follo
File test operations-advanced bash Script Programming Guide
/Span> 7.2 file testing operations----------------Returns true if...-E file exists-File a exists.This option has the same effect as-e, but it has been discarded and is not encouraged.-F file is a regular file (not a directory or a device file)-S file length is not 0-D files are directories.-File B is a block device (floppy disk, cdrom, etc)-The c f
Bash script programming Step-by-step articlefunction, array, string manipulationfunction: functions in scripting are fundamentally different from the functions in our math. The functions here are mainly for the purpose of implementing procedural programming code reuse. For example, a function to calculate a number, when we need to use the calculation of numbers,
Programming styleProgram programming to solve problemsThe instruction organizes the data, the instruction is stackedTo complete a complex taskSequential execution: Traversing execution, running one by oneSelect execution: There is a selection criteria, the result can only have one choice, only to execute some code fragmentsLoop execution: Run the same operation on a class of objects one by one, similar to t
In bash programming, it often involves using while statements to deal with the number of unknown loops at times.
While syntax
While [Express]do#commanddone2. Practical Practice
Prompt to enter an integer greater than 10 less than 20;
While1.sh:#!/bin/bashecho-n "Please input a digit between:" Read Nwhile [$n-lt 10]| | [$n-gt]doecho-n "Please input a digit between an
~/tscripts $ unset namereadonly6. Non-read-only variable can be canceled, cancel print to empty[Email protected] ~/tscripts $ unname=~/~/tscripts $ echo $unname7. Single quotation marks~ $ name='Leo'$name ' $'name'8. Double quotes" I am $name " "\\i am $name \ \"\i am Leo \9. Stitching strings" He is $name " is "$name is handsome"! is handsome! "$name is handsome! "-bash:! " : Event not found10. Get the string length[Email protected] ~ $ echo ${
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.