Shell Programming Notes (four) __ programming

Source: Internet
Author: User

echo Color output position parameter variable a predefined variable read accept script arguments enter declare source command

echo Color Output

I just found out today . Echo can also output a string with a color :

Echo-e "asdasd\e[1;32m ABCD \e[0m"

Using the-e option, \e[1;32m \e[0m This is a color wrapping format, 32m is the color code, the Internet can find other colors, output results:

Also learned the Bash_history file, which contains the shell command history, the command executed by default will be saved to the file after logging off, but we can directly execute history-w before logging off to the. bash_history file

$ () and inverted quotation marks are the same, the recommended use of $ ()
Positional parameter Variables

$n $* $@ $#

The above four positional parameter variables represent, the nth parameter parameters passed in, all parameters passed in, each parameter passed in, the number of parameters passed in

#!/bin/bash for
i in ' $* '
        do
                 echo ' The parameter is: $i '
        done

x=1 to Y in $@ do
                Echo ' The parameter$x is: $y "
                x=$ (($x + 1))
        done

From the script above we can see that there is a difference between $* and $@, $* all parameters as a whole, so the loop executes only one predefined variable

$? $$ $!

The above three predefined variables represent the execution result of the previous command (0 for correct execution, not 0 for error execution, which is not 0 for the command itself), PID of the current process, PID read of the last process executing in the background.

#!/bin/bash
read-t 6-p "Please input your name:" Name
echo $name

echo-e "\ n"
read-s-t 6-p "please en ter your age: ' Age
echo ' is $age "

echo-e" \ n "
read-n 1-t 6-p" Please select your gender[m/f]: "gender< C10/>echo "Sex is $gender"
-N-T-P

The above three options represent the number of parameters to be read, the length of time to wait for input, and whether the input is confidential (does not echo characters when entered) declare

Usage declare [+/-][options]

-Give variable type
+ Cancel variable type-i
declare variable as integer-X to
declare variable as environment variable
-p to view the value of a variable


One of the most common numerical methods we use is this:

aa=11
bb=22
cc=$ (($aa + $bb))

Note: The space between AA and A and AA and BB is not to be omitted
There is also a way to use expr:

cc=$ (expr $aa + $bb)

spaces cannot be omitted Source Command

In a bunch of cases, after you change the configuration file, it will not take effect to log off again, but we can use the source command directly to make the configuration file take effect directly

SOURCE Conf_file
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.