sh、bash使用介绍 shell会话介绍 echo、printf、tee终端打印

2015-08-10 22:14:00
admin
原创 3117
摘要:sh、bash使用介绍 shell会话介绍 echo、printf、tee终端打印

一、sh、bash使用介绍

1、sh,Bourne shell的缩写,unix标准shell;

2、bash,GNU Bourne-Again SHell的缩写,linux标准shell;

3、Bash is an sh-compatible command language interpreter.

4、Bash incorporates useful features from the Korn and C shells (ksh and csh).

5、sh/bash [options] [file],执行一个脚本,自动继承环境变量;

6、sh/bash [options] -c string,执行一个字符串,自动继承环境变量;


查看支持的shell:cat /etc/shells

/bin/sh
/bin/bash
/sbin/nologin


查看当前的shell:echo $SHELL

/bin/bash


查看shell实际情况:ls -l /bin/sh /bin/bash

/bin/bash

/bin/sh -> bash


二、shell会话介绍

1、当前shell起的进程会话ID是当前shell的PID,包括直接和间接起的进程;

2、当前shell起的后台进程会话ID是当前shell的PID,包括直接和间接起的后台进程;

3、会话ID不会变,即使shell已经关掉;

4、查看进程会话ID:ps -o pid,ppid,sid,stime,cmd -C 进程名


三、终端打印

echo输出任意字符:

echo -ne "\x30\x31\x32\x33\n",n不换行,e支持转义字符,输出0123


printf格式化输出:

printf "%02X\n" 15,输出0F

printf "\x30\x31\x32\x33\n",输出0123


tee复制输出到文件:

ps -ef | tee one.txt two.txt,同时输出内容到标准输出、one.txt、two.txt

发表评论
评论通过审核之后才会显示。