1. The concept of variables: variables are stored in the program of the user's memory space, the variable name is the address of this memory space, the value of the variable is stored in the computer memory. Variable definition: It is simple to understand that a variable is a key-value relationship pair in memory, as follows a can be understood as its in-memory address, 1 for its specific content.
[[email protected] ~]# A=1[[email protected] ~]# echo $A1
2. Variables and quotation marks: There are three kinds of quotation marks in the shell, single quotation mark ', double quotation mark "" and "anti-quotation mark" `,其中单引号括起来的字符都作为普通字符出现;双引号括起来的字符除了$ \
, these characters still retain their special function, the remaining characters are still normal characters, the contents of the anti-quotation marks are first interpreted by the shell as command execution, and their output as the subsequent input.
双引号"$ \ `` ‘‘ 可以转义 "[[email protected] ~]# str="hello world"#被双引号括起来的 hello+空格+world 作为一个字符串赋值给了str[[email protected] ~]# echo $strhello world
反引号``[[email protected] ~]# pwd/root[[email protected] ~]# MyDir=`pwd`#pwd命令获取当前的目录位置,然后把该位置赋值给MyDir[[email protected] ~]# echo $MyDir/root
综合的#!/bin/bashD="Play"A=""pwd"+‘pwd‘+`pwd`-$D-"$D"-‘$D‘-`$D`"echo $A结果:[[email protected] ~]# sh test.sh test.sh: line 3: Play: command not foundpwd+‘pwd‘+/root-Play-Play-‘Play‘-
Shell Learning variables and quotes