重定向与管道

stdin、stdout、stderr

标准输入、标准输出、标准错误

 

重定向-stdin

结果不想输出到终端上(命令结果要处理)

使用shell 的重定向

ps -ef >out 也可以ps -ef 1 >out      > 为重定向符     ps -ef命令输出的数据导入到out文件中而不是显示在终端上

0 - stdin; 1 - stdout; 2 - stderr

/dev/null    像是黑洞,不占内存

追加方式重定向  而不是覆盖>>

 

重定向-标准错误

同时重定向stdout和stderr到同一个文件

command > both 2>&1     &防止把2重定向到1中     1不是文件

注意次序 从左到右 :   反过来不行  command  2>&1 >both

command &>both(bash4支持)

 

同时重定向stdout/stderr到不同的文件

command >out 2>err

 

重定向-stdin

python readadd.pay < readadd.dat

 

管道

将一个命令的输出的内容,给另一个命令作为输入的内容进行处理

ps - ef 和  grep python 

  ps -ef > tmp.out

也可以   ps- ef |grep python

 

连续管道

也可以   ps- ef |grep python   |  grep -v grep

 

环境变量

什么事shell环境变量

特殊意义的变量用来影响进程得到行为,可以传递给子进程

printenv

环境变量是如何生成的

操作系统为每个进程保存

每个进程可能会修改环境变量,通过初始化脚本或者用户操作

子进程继承父进程的环境变量

 

临时添加环境变量

export  PATH=./:$PATH       ./      环境变量分割用  :

永久添加环境变量

login shell

/ect/profile ,  ~/.bash_profile,  ~/.bash_login, ~/.profile    一般放入~/.bash_profile    ~当前用户根目录

 

non-login shell

  ~/.bashrc

echo $0 来区分  -bash 与bash

source  .bash_profile   立刻生效

 

环境变量 ps1

echo $ps1

  \u   当前用户

  \h  主机名

  \w   当前路径

  \t   当前时间

export   ps1="\u \w"

export ps1="\e[0;36m\u \w> \e[m"

posted @ 2020-09-13 22:17  寂静音无  阅读(108)  评论(0)    收藏  举报