PS1 = "[\t][\u]\$"//New shell prompt shows the current time and user nameIn Windows, you often see such file paths: D:\work\FTL Moniqi\ftl_lru-0513\ftl_lru-0513\siLinux takes a different approach. Linux stores files in a single directory structure, a directory that we call virtual directories. The virtual directory contains the file paths for all storage devices installed on the PC.Linux uses the forward slash "/" instead of the backslash "\" to plan
Bit left shift
>>
Bit right Shift
Bit Boolean and
|
Bit Boolean or
Logic and
||
Logical OR
Code 2-11[Email protected]:/data# cat Demo3 #!/bin/bashval1=10if (($val 1 * * 2 >) then ((val2= $val 1 * * 2)] echo "The sq Uare of $val 1 is $val 2 "Fi[email protected]:/data#./demo3 the square of 100 use both brackets[[Expression]] provides another feature
1. After opening the terminal prompt, $ represents a normal user, #表示管理员用户root, root is the most privileged user in the Linux system.2. A shell script is usually a text file with a #! start, where #! precedes the interpreter path. Example: #!/bin/bash3. Note section starts with #, and consistently continues to the end of the line4. By default, Echo adds a line break after each call. The text after echo can be enclosed in double quotation marks, with s
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
The remaining space is Morethan the%, the message is sent to the Wl#tue2 the: $: AboutCst .PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport PATH forRemainingspaceinch$(DF-H |awk '{print $}'|grep-V' Use'|sed-E's/[%]//g') Do if[[$RemainingSpace > the]]; Then Echo-E"$RemainingSpace" Echo-E"$ (df-h | grep $RemainingSpace)">/service/script/. Harddiskwarning Mail-S"Disk Warning"WL . Harddiskwarningfi Done4. Detecting remaining Inode#!/bin/Bash#inspcet Inode
. Useful Scenario 2:now there are 1000 boards shipped to be labeled, and the MAC address was not recorded for some reason. This time how to do, it is not possible to go to the landing copy and paste. Save it to the printer, a script print out, it's so wayward SSH login execute ls command :echo y| plink-ssh [email protected]-PW password lsSSH Login Run command.txt command in turn:echo y| plink-ssh [email protected]-PW password-m command.txttelnet Login to execute ifconfig and exit:? Echo ' ifcon
]:~/learn$ cat Args.txt | Xargs SH cecho.sh;Arg1 arg2 arg3#Requirement 3, how do I embed parameters in a fixed command line? As shown below:Copy CodeThe code is as follows:[Email protected]:~/learn$ sh cecho.sh-p args1-1-P args1-1#[Email protected]:~/learn$ sh cecho.sh-p args2-1-P args2-1#[Email protected]sli-pc:~/learn$ sh cecho.sh-p args3-1-P args3-1#Solutions for using Xargs:Copy CodeThe code is as follows:[Email protected]:~/learn$ cat Args.txt | xargs-i {} sh cecho.sh-p {}-1-P arg1-1#-P arg
'; DoIf ID $DUSER >/dev/null; ThenUserdel-r $DUSER[$DEBUG-eq 1] echo "Delete $DUSER finished."Else[$DEBUG-eq 1] echo "$DUSER not exists."FiDoneFiecho "$DEBUG add: $ADD del: $DEL"[Email protected] ~]#/adminuser33.sh-v--add tom2,tom3--del tom2ADD user Tom2 finished.ADD user Tom3 finished.Delete Tom2 finished.1 add:1 del:1Exercise: Write a script showlogged.sh , which is in the following format:Showlogged.sh-v-c-h|--helpamong them, - H option can only be used alone to display help information; -
updated successfully.Changing password for user bruce03.Passwd:all authentication tokens updated successfully.Changing password for user bruce04.Passwd:all authentication tokens updated successfully.Changing password for user bruce05.Passwd:all authentication tokens updated successfully.Changing password for user bruce06.Passwd:all authentication tokens updated successfully.Changing password for user bruce07.Passwd:all authentication tokens updated successfully.Changing password for user bruce0
-nand 11 use, tell read command to accept single word specifier exitCode 2-25[Email protected]:/data# cat Demo5 #!/bin/bashread-n1-p "Do you want to continue [y/n]" Answercase $answer in y|y) E Cho echo "fine,continue on ...";; N|n) echo echo "Ok,goodbye" exit;; Esacecho "This is the end of the script" [email protected]:/data#./demo5 does you want to continue [y/n]yfine,continue on]. . This is the end of the script Hidden mode read, the-S optio
used with variable names, and if the loop body does not include a variable name, a dead loop may occurHow the list is generated:1) Give a direct2) List of pure integersSEQ: Output An integer listseq [First [INCREMENT]] Last3) curly braces unfold{first.. Last}4) return value of the execution result of the command5) GLOBBING6) references to certain variables: [email protected], $*Features of the For loop:1. There is almost no cycle of death;2. The entire list needs to be loaded into memory during
Learn more about the character test of Linux and the practice of bash scriptingOne, character test options= =: Tests whether two strings are equal, equals true, and not equal to false.! =: Tests whether two strings are unequal, unequal to true, and equal to false.-N String: Tests whether the specified string is empty, NULL is true, and is not NULL for false.-Z String: Tests whether the specified string is not empty, is not empty, is true, and Null is
read file instead of the screen outputCommon Command options:P Print matching linesA newc instead of one lineD Delete Anchor rows replaces some parts of a row2.6.1sed-Example1. Displaysed-n ' 2p ' tmp.txt show only line 2ndsed-n ' 1,3p ' temp.txt print lines 1th through 3rdsed-n '/mov/' p temp.txt print lines with movie2. Deletesed ' 2d ' tmp.txt Delete line 2ndsed ' 3,d#x2032;tmp.txt#x5220;#x9664;#x7B2C;3#x884C;#x5230;#x6700;#x540E;#x4E00;#x884C;#xFF0C;">D′TMP.TXTBy deletingExceptThe3YesToMost
; Thenuserdel-r $USER [$DEBUG-eq 1] ECho "Delete $USER finished." else[$DEBUG-eq 1] echo "$USER not exist." Fidonefi Exercise: Write a script showlogged.sh, which uses the format: Showlogged.sh-v-c-h|--help where the-h option can only be used alone to display help information; the-C option displays the number of users logged on on the current system If you use the-V option at the same time, both the number of simultaneous users logged in and the information about the logged-on user are display
can download the code for this example from here. Example Two: colorful Scripts Linux terminals also support colorful, please see the following script: #!/bin/bashClearEcho-e " #092; #048; 33[1m Hello World"# Bold EffectEcho-e " #092; #048; 33[5m Blink"# Blink effectEcho-e " #092; #048; 33[0m Hello World"# Back to NoramlEcho-e " #092; #048; 33[31m Hello World"# Red ColorEcho-e " #092; #048; 33[32m Hello World"# Green ColorEcho-e " #092; #048; 33[33m
Write a script:1. Add 10 users user1 to User10, password with user name, but only if the user does not exist to add;#!/bin/bash# forIinch{1..Ten}; Do if!IDUser$i >/dev/NULL; ThenUseradd user$iEcho "user$i"|passwd--stdin user$iElse Echo "User$i exists" fi DoneDelete the above 10 users#!/bin/bash# forIinch{1..Ten}; Do if IDUser$i >/dev/NULL; ThenUserdel-r user$i >/dev/nullEcho "user$i deleted" Else Echo "user$i NOT EXISTS" fi DoneExtension: Adds or deletes a specif
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.