Linux Shell 学习笔记 00

一、Bash = Bourne Again SHellshell

二、终端提示符:bash

#普通用户
username@hostname$
#管理员用户
root@hostname#

三、shell脚本一般是一个以shebang起始的文本文件:blog

#!/bin/bash

shebang是一个文本行,其中#!位于解释器路径以前。/bin/bash是bash的解释器的命令路径。字符串

在Unix行话中,字符“#”一般读做“sharp”或“hash”或“mesh”来称呼,惊叹号“!”称为bang,“shebang”是指这两个字符合起来“#!”。hash

四、将字符串写入文本:it

echo "This is a sample text!" > temp.txt 

将字符串插入文本后面:class

echo "This is another sample text!" >> temp.txt

查看文本文件内容:终端

cat temp.txt

将错误信息stderr从新定向到文本中:数据

$ ls + 2> out.txt

ls + 是一条错误语句,“2>”是stderr从新定向符。脚本

/dev/null 是一个特殊的设备文件,它接收到的任何数据都会被丢弃,被称为设备黑洞。数据一去不复返。

五、在脚本中生成延时:

#!/bin/bash

echo -n Count:
tput sc

count=0;
while true;
do
    if [ $count -lt 40 ];
    then
        let count++;
        sleep 1;
        tput rc
        tput ed
        echo -n $count;
    else exit 0;
    fi
done
相关文章
相关标签/搜索