Bash Shell 内置变量命令

2019-11-16  本文已影响0人  August________

Bash Shell 内置变量命令

echo在屏幕上输出信息

参数选项 说明
-n 不换行输出
-e 解析转义字符
转义字符
\n 换行
\r 回车
\t 制表符
\b 退格
\v 纵向制表符
# echo shell;echo bash
shell
bash
# echo -n shell;echo bash
shellbash
[root@lhf test]# echo "shell\tbash\nshell\tbash"
shell\tbash\nshell\tbash
[root@lhf test]# echo -e "shell\tbash\nshell\tbash"
shell   bash
shell   bash
# printf "shell\tbash\nshell\tbash\n"
shell   bash
shell   bash
[root@lhf test]# echo -e "1\b23"
23
[root@lhf test]# printf  "1\b23\n"
23
[root@lhf test]# echo -e "1\b23"
23
[root@lhf test]# printf  "1\b23\n"
23

eval

[root@lhf test]# cat novel.sh 
echo \$$#
[root@lhf test]# bash novel.sh 1 2
$2
[root@lhf test]# cat eval.sh
eval "echo \$$#"
[root@lhf test]# bash eval.sh 1 2
2


exec

[root@lhf test]# su - lhf
[lhf@lhf ~]$ exec date
Sat Nov 16 23:05:38 CST 2019
[root@lhf test]#
[root@lhf test]# seq 5 > /tmp/tmp.log
[root@lhf test]# cat exec.sh 
exec < /tmp/tmp.log
while read line
do
    echo $line
done
echo ok
[root@lhf test]# bash exec.sh 
1
2
3
4
5
ok

read

shift

[root@lhf test]# bash shift.sh 1 2
1 2
2
[root@lhf test]# cat shift.sh 
echo  $1 $2
if [ $# -eq 2 ];then
    shift
    echo $1
fi
[root@lhf test]# bash shift.sh 1 2
1 2
2


上一篇 下一篇

猜你喜欢

热点阅读