]shell]#catfun1.sh#/bin/bashread-p "Please enter the network card:" networkip () {ifconfig $network |head-2|tail-1|awk -F ': ' ' {print$2} ' |awk ' {print$1} '}case $network ineth* ) echo "This is the Ethernet NIC," ipaddr= ' ip $network ' echo ' $network IP is: $ IPAddr ";; lo) echo "This is the loopback network card" ipaddr= ' ip $network ' echo "$network IP is: $ipaddr" ;; *) echo "You entered the incorrect, please new input!" ";; EsacExtended Learning:Select is also a kind of loop, it is
$#
The number of arguments passed to the script or function
$*/[email protected]
All parameters passed to the script or function. When enclosed by double quotation marks (""),[email protected] is slightly different from $*
$$
The current shell process ID, which is the process ID for the shell script, which is where these scripts are located
Take a look at the following script:#!/bin/bashecho "File Name: $0"echo "First Parame
much like a C-language functional pointer? Like the C language, Lua's functions can accept a variable number of parameters, which are also defined by "...", such as:function sum (A, B,...)If you want to get ... Represents the parameter that can be obtained by accessing the ARG local variable (table type) in the function.such as SUM (1,2,3,4)Then, in the function, a = 1, b = 2, arg = {3, 4}More valuable is that it can return multiple results at the same time, such as:function S ()Return 1,2,3,4E
script requires a user name list file as a parameter2) If no parameters are provided, this script should give a hintUsage:/root/batchusers, exit and return the corresponding value3) If a nonexistent file is provided, this script should give aShow Input file not found, exit and return the corresponding value4) New User login Shell is/bin/false, no need to set password5) User list test file:Http://classroom/pub/materials/userlist# wgethttp://classroom/pub/materials/userlist[Email protected]/]# vi
listDoCommand sequenceDoneFor a in Zhangsan Lisi Wangwu DCDoUseradd $aDoneVariable a participates in the loop, and the variable a value affects the result of the loop[Email protected]/]# vim/root/for.sh#!/bin/bashFor a in Nsd11 nsd12 nsd13 nsd15DoUseradd $aEcho $a created successfullyDoneVariable A does not participate in the loop, and the variable a value does not affect the result of the loop#!/bin/bashFor a in 1 2 3Do echo hello worlddone[Email protected]/]# cat/root/num.sh#!/bin/bashnum
Http://classroom/pub/materials/userlist[Email protected]/]# vim/root/batchusers#!/bin/bashIf [$#-eq 0];then//$ #位置变量的数量, when no arguments are provided, the $ #为0, the expression is setEcho ' Usage:/root/batchusers ' >2//output Usage:/root/batchusers >2 into error outputExit 1//Return value 1, prompt for wrong input parameterselif [!-F $];thenEcho ' Input file not found ' >2Exit 2FiFor a in $ (cat $)DoUseradd-s/bin/false $aEcho $a created successfullyDone########################################
whether the VSFTPD service is running, if it has been run to list its listening address, PID number, otherwise the output hint "VSFTPD service is not available!" ”First install the VSFTPD software, turn on the VSFTPD service (software CD)Then write the script vim chkftpd.sh[Email protected] ~]# chmod +x chkftpd.sh[Email protected] ~]#./chkftpd.shJINGGAO:VSFTPD fuwubukeyong!Set permissions and execute to prompt vsftpd service not availableExecute script again after opening VSFTPD server3. Multi-
command. You can use Echo to print any variable value in any place where you suspect it is wrong. That's why most shell programmers spend 80% of their time debugging programs. of the Shell programThe advantage is that there is no need to recompile, and it does not take much time to insert an echo command.The shell also has a real debug mode. If there is an error in the script "Strangescript", you can debug it this way:
Sh-x Strangescript
This executes the script and displays the values of all v
.txt[[emailprotected] sbin]# ./05.expect 192.168.242.129 /tmp/123.txtspawn rsync -av /tmp/123.txt [emailprotected]:/tmp/123.txt[emailprotected]‘s password: sending incremental file list123.txtsent 71 bytes received 31 bytes 204.00 bytes/sectotal size is 0 speedup is 0.00Iii. building a file distribution system
Requirements background: For large companies, there must be a site or configuration file updates from time to time, and the use of the machine is certainly a lot of units, fewe
Caimont The idea of writing an article, after receiving the strong support of Mr. Hongbin of Chinabyte Network College, you will be able to see this article.
The author earnestly hopes that through this article for the vast number of WEB developers and enthusiasts to provide convenience, to enable everyone to participate in the study and exchange of ASP, in order to cover the needs of readers at different levels the author decided to start from the most basic
(i) deletion and addition of elements in an array#代表创建一个数组, containing 1 to 4 elementsPS c:\windows\system32> $num =1..4#查看创建好的数组PS c:\windows\system32> $num1234#删除数组的第三个元素, note that is counted starting from 0, the above definition of the array has 4 elements, then the count is 0,1,2,3, so this removes the third element, is to preserve the 0,1,3 element, delete the 2nd elementPS c:\windows\system32> $num = $num [0..1]+ $num [3]#再次查看, you can see that a third element has been deletedPS c:\window
In a later tutorial, I'll focus on how the PowerShell script is written. This section, first do an overview and the general introduction, today is a holiday, not to write too much, tomorrow began to explain.
PowerShell Scripting Basics Overview:
constants, variables, arrays, hashes
Conditions, logic
only numbers, letters, or underscores, and cannot start with a number3, as far as possible to see the name of the ideaVI. Bash configuration files1. Profileclass : Provides configuration for the interactive login shell process.• Valid profiles for all users are globally valid:/etc/profile and/etc/profile.d/*.sh• Only the profile that is valid for the current user is valid for the user: ~/bash_profileNote: The function of profile type configuration file:(1) To define environment variables(2) run
it into a string$# number of parameters after output script[email protected] references all parameters after the script, but one reference$? Output previous command execution status return codeNumeric operationsLet VAR=ARG1+-*/%ARG2var=[$a + $b]var=$ (($a + $b))var=$ (expr ar1 ar2 ...)Logical operations | | Or! Non -Pstree Show Process TreeExport displays all of the current environment variablesUnset the variables that were set before the undoReadOnly setting read-only variablesDeclare-R Set re
seconds, in the shell script of the usual term loop.At this point, you press CTRL +z to pause it, and then enter BG to go back into the background.In the case of multitasking, if you want to move the task to the foreground, FG is followed by the task number and the task number can be obtained using the jobs command.9. >>, 2>, 2>> : The above-mentioned directional symbols > and >> denote the meaning of substitution and addition, then there are two symbols which are 2> and 2>> here. Indicate erro
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.