echo  -n  "hello"    加上-n可以不输出换行,让下一行的输出紧挨着上一行。

set    输出环境变量

echo  "This is \$20"    加反斜杠输出$字符

${variable}    引用变量


命令替换:

echo "now time is `date`"        连同命令一起输出

echo "now time is $(date)"      连同命令一起输出

echo "now time is $time"        连同变量一起输出

variable=`date`          命令结果赋值给变量

variable=$(date)        命令结果赋值给变量

today=$(date +%y%m%d)        格式化日期

使用命令替换会产生子shell


输出重定向和输入重定向:

输出重定向:

date  >  test.txt        将结果输出到文本中

date  >>  test.txt      将结果追加到文本中

输入重定向:

command  < filename        将文本内容输入到命令

例:wc  <  text.txt

内联输入重定向:

command  <<EOF

content

EOF

例:

wc  <<EOF

hello world!

hello world!

EOF

EOF为任意字符但结尾字符必须和开头字符相同


内联重定向到文件:

cat >> demo.txt <<EOF

some content

EOF

例:

outfile='data.sql'

IFS=','

while read name sex age height

do

        cat >> $outfile  <<EOF

INSERT INTO tablename(name, sex, age, height) VALUES('$name', '$sex', '$age', '$height');

EOF

done  < ${1}


管道符:

rpm  -qa  |  sort    将第一个命令的输出传给第二个命令处理,两个命令其实是同时在执行