Shell programming in the 3rd chapter of Shell Variable Foundation (bottom)

Source: Internet
Author: User

1. Two methods of setting login prompt
(1)/ETC/MOTD
[[email protected] thzzc]# echo this is THZZC test Linux >/ETC/MOTD
[Email protected] thzzc]# CAT/ETC/MOTD
This is THZZC test Linux
(2)/ETC/PROFILE.D
[Email protected] home]# echo echo This is THZZC test Linux >/etc/profile.d/test.sh
[Email protected] home]# cat/etc/profile.d/test.sh
echo This is THZZC test Linux
2, single quotes, double quotes, non-quoted differences example
(1) [[email protected] ~]# cat test.sh
a=192.168.1.1
b= ' 192.168.1.1 '
C= "192.168.1.1"
echo a= $a
Echo b= $b
Echo c= $c
[Email protected] ~]# sh test.sh
a=192.168.1.1
b=192.168.1.1
c=192.168.1.1
(2) [[email protected] ~]# cat test.sh
a=192.168.1.1
A=192.168.1.1-$a
b= ' 192.168.1.1-$a '
c= "192.168.1.1-$a"
echo a= $a
Echo b= $b
Echo c= $c
[Email protected] ~]# sh test.sh
a=192.168.1.1-192.168.1.1
B=192.168.1.1-$a
c=192.168.1.1-192.168.1.1-192.168.1.1
3. awk single quote, double quotation mark abnormal case
[Email protected] ~]# oldboy=123
[[email protected] ~]# awk ' BEGIN {print ' $oldboy '} '
$oldboy
[[email protected] ~]# awk ' BEGIN {print $oldboy} '

[[email protected] ~]# awk ' BEGIN {print ' $oldboy '} '
123
[[email protected] ~]# awk ' BEGIN {print "' $oldboy '"} '
123
With awk, the opposite is the case, with single quotes, double + single resolution variables, and double quotes as output. Nothing adds output to null.
Summary: If you want to output the same as the double quotation marks, the resolution variable with double + single (' xxx ')
The old boy for convenience, generally not directly with awk, but using the method of the pipeline, first echo variable let the pipeline through the second pass the parameter.
[Email protected] ~]# oldboy=123
[[email protected] ~]# echo $oldboy |awk ' {print $} '
123
[[email protected] ~]# echo ' $oldboy ' |awk ' {print $} '
$oldboy
[[email protected] ~]# echo "$oldboy" |awk ' {print $} '
123
Both SED and grep are consistent with previous conclusions, and awk is odd. Awk is really a language!

Shell programming in the 3rd chapter of Shell Variable Foundation (bottom)

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.