Reference usage description for shell scripts

Source: Internet
Author: User

#!/bin/bash
#演示全引用和部分引用
#双引号和没引号的区别
variable1=2010
echo "$variable 1"
echo $variable 1
variable2= "x y z" # #字符之间用多个空格隔开
echo "$variable 2" # #双引号
echo $variable 2 # #没引号

#单引号和双引号的区别
echo "$PWD is the current directory." # #双引号
Echo ' $PWD is the current direcotry. ' # #单引号

#单引号的问题和解决方法
echo "Why can ' t I write ' s between single quotes" # #单引号出现的问题
Echo ' Why can ' ' "'" ' t I write ' "'" ' s between single quotes ' # #解决单引号的问题

# #命令替换
#反引号的用法
Echo ' World ' # #调用world命令
Echo ' Who ' # #调用who命令

#字符串分割问题与解决办法
Echo ' Echo ' # #表示将结果以字段显示
echo "' Echo '" # #表示将结果以字符串显示
Echo ' echo x y ' # #表示结果是x y two strings
echo "' Echo x y '" # #表示结果是x y as a string

dirlist= ' ls-l * ' # #命令替换
Echo $dirlist # #不引用dirlist变量, line break is deleted
echo "$dirlist" # #引用dirlist变量, line break retention

#$ () 's Embedding method
firstlinelength=$ (expr Length "$ (sed-n ' 1p ' *)")
Echo $firstlinelength

#转义
echo \ # #输出转义符
echo ' echo \ \ ' # #输出空本行
echo $ (echo \ \) # #输出单斜线符

#转义符的运用
echo "\ $PWD" # #转义 $ symbol
echo "This was \" The 60th National day\ "# #转义双引号"
echo "\ \" # #转义符号本身
Variable=\ # #将转义符赋值给变量

#将一串符号赋值非变量
Variable= "() \\{}\$" "
Echo $variable
echo "$variable"

Ifs= ' \ '
Echo $variable
echo "$variable"


This article is from the "All Night" blog, please make sure to keep this source http://endmoon.blog.51cto.com/8921900/1616630

Reference usage description for shell scripts

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.