单引号 ' ' :强引用是能识别命令本身单词(六亲不认,写什么是什么)
双引号 " " :弱引用能够识别变量
反向单引号 ` `:识别命令本身
$ : 调用变量本身
\ :转义符(转义符号本身意思)
; :命令与命令之间在同一终端命令行中多个命令使用
`` 和 $()
把一个命令的输出打印给另一个命令的参数,放在 `` 中一定是有输出的命令
$(COMMAND) 或 `COMMAND`
实例:
[root@centos8 ~]#ll `echo `date +%F`.txt`
-bash: .txt: command not found
ls: cannot access 'date': No such file or directory
ls: cannot access '+%F': No such file or directory
[root@centos8 ~]#ll $(echo $(date +%F).txt)
-rw-r--r-- 1 root root 0 Mar 20 09:55 2020-03-20.txt
[root@centos8 ~]#ll `echo $(date +%F).txt`
-rw-r--r-- 1 root root 0 Mar 20 09:55 2020-03-20.txt
[root@centos8 ~]#ll $(echo `date +%F`.txt)
-rw-r--r-- 1 root root 0 Mar 20 09:55 2020-03-20.txt
“ ” ,‘ ’, ``三者区别
[root@centos8 ~]#echo "echo $HOSTNAME"
echo centos8.localdomain
[root@centos8 ~]#echo 'echo $HOSTNAME'
echo $HOSTNAME
[root@centos8 ~]#echo `echo $HOSTNAME`
centos8.localdomain
口诀:
单引号:六亲不认,变量和命令都不识别,都当成了普通的字符串
反向单引号:变量和命令都识别,并且会将反向单引号的内容当成命令进行执行后,再交给调用反向单引号的命令继续
双引号:不能识别命令,可以识别变量
实例:
[09:18:04 root@centos8 data]#echo "This system's name is $(hostname)"
This system's name is centos8.magedu.org
[09:18:55 root@centos8 data]#echo "I am `whoami`"
I am root
[09:15:37 root@centos8 data]#touch $(date +%F).log
[09:16:29 root@centos8 data]#ls
2019-12-13.log
[09:16:31 root@centos8 data]#ll
total 0
-rw-r--r--. 1 root root 0 Dec 13 09:16 2019-12-13.log
[09:16:34 root@centos8 data]#touch `date +%F`.txt
[09:17:14 root@centos8 data]#ll
total 0
-rw-r--r--. 1 root root 0 Dec 13 09:16 2019-12-13.log
-rw-r--r--. 1 root root 0 Dec 13 09:17 2019-12-13.txt
[09:17:15 root@centos8 data]#touch `hostname`-`date +%F`.log
[09:18:02 root@centos8 data]#ll
total 0
-rw-r--r--. 1 root root 0 Dec 13 09:16 2019-12-13.log
-rw-r--r--. 1 root root 0 Dec 13 09:17 2019-12-13.txt
-rw-r--r--. 1 root root 0 Dec 13 09:18 centos8.magedu.org-2019-12-13.log
[root@centos8 ~]#touch `date +%F_%H-%M-%S`.log
[root@centos8 ~]#touch `date -d '-1 day' +%F`.log
括号:{ }
1.{} 可以实现打印重复字符串的简化形式
例:
[root@centos8 ~]#echo {000..20..2}
000 002 004 006 008 010 012 014 016 018 020
[root@centos8 ~]#echo {a..z..2}
a c e g i k m o q s u w y
[root@centos8 ~]#echo {A..z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i
j k l m n o p q r s t u v w x y z
2.关闭和启用{}的扩展功能
{}的功能变量为$-
正常为:
[root@localhost ~]# echo $-
himBH
关闭:set +B
关闭后:
[root@localhost ~]# echo $-
himH
[root@localhost ~]# echo {1..10}
{1..10}
恢复:
[root@localhost ~]# set -B
[root@localhost ~]# echo {1..10}
1 2 3 4 5 6 7 8 9 10