Some tips in the shell

Source: Internet
Author: User
Tags function definition

Bash is currently a more popular type of shell under Linux, and the following are some of the scattered things that are recorded in the learning process. Tidy up for forgetting!

1. Transfer of function parameters

1) Variables in the script that precede the function definition are available in the function

2) function to run the required parameters, can be $, $, $ ... To pass

3) Variable settings keywords should avoid system variables to avoid errors

4) keyboard reading of variables

READ-P/-T variable

-P Follow-up prompt

Number of seconds to wait after-t

Reference script (command) parameters

The $ A Script (command) itself

The first logarithm of a script (command)

$

$? Read exit code of last execution command, 0 for success other for failure

2.bash arrays

Statement

DECLARE _a array

(You can also assign a variable directly to an array by not declaring it.)

Assign value

1) array = (var1 var2 var3 ...)

2) array = ([0]=var1 [2]=var2 ... )

3) Array[0]=var1

referencing arrays

Echo ${array[n]}

Iterating through an array

Filename= (' ls ')

For Var in ${filename[@]};d o #@/*---expansion position logarithm, starting from 1

Echo $var

Done

Various symbols in the 3.shell

code block

{} Unable to open a new shell properly

[]test,test's expression will be in []. [] is part of the shell built-in test command, not a connection to the/usr/bin/test, [followed by a space,] a space before

[] array elements

[] Character Range

(()) Data calculation extension, (()) using a numeric calculation

"" Strong reference (preserves whitespace in the variable)

' Weak references '

Meaning of the 4.bash exit code

1 General error

2shell built-in command use error

126 command call cannot be performed

127command not found

Parameter Error in exit

130 using Ctr+c to end the script

255 out of range exit status



Ps:shell script is an administrator to complete the management of the server is very important content, the full use of the script can make you become a lazy administrator, this is the path to success.


Some tips in the shell

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.