Shell Start-Up
时间:2008-08-01 来源:angelboycn
变量
变量引用用$号,赋值不需要:
$ read salutation
Wie geht’s?
$ echo $salutation
Wie geht’s?
引用
引用分为''和""两种,含义不一样:双引号引用的字符串里面的$变量会被替代,而单引号引用的则不会,另外还可以用\$解除双引号里的变量替代:
#!/bin/sh
myvar=”Hi there”
echo $myvar
echo “$myvar”
echo ‘$myvar’
echo \$myvar
echo Enter some text
read myvar
echo ‘$myvar’ now equals $myvar
exit 0
输出:
Hi there
Hi there
$myvar
$myvar
Enter some text
Hello World
$myvar now equals Hello World
变量引用用$号,赋值不需要:
$ read salutation
Wie geht’s?
$ echo $salutation
Wie geht’s?
引用
引用分为''和""两种,含义不一样:双引号引用的字符串里面的$变量会被替代,而单引号引用的则不会,另外还可以用\$解除双引号里的变量替代:
#!/bin/sh
myvar=”Hi there”
echo $myvar
echo “$myvar”
echo ‘$myvar’
echo \$myvar
echo Enter some text
read myvar
echo ‘$myvar’ now equals $myvar
exit 0
输出:
Hi there
Hi there
$myvar
$myvar
Enter some text
Hello World
$myvar now equals Hello World
相关阅读 更多 +