shell基本概念

一、shell分类

常见shell:bash、zsh、tcsh

linux默认:bash shell

#tcsh

#bash

#pstree | grep login

|- .. ..

|-login---bash---tcsh---bash-+-grep

#!/bin/bash   //声明shell环境

二、运行shell脚本:

1.作为指定shell解释程序的参数

1)sh 文件代码路径 ====  bash 文件代码路径

2). 代码文件路径 ==== source代码文件路径

#sh /root/script.sh 

2.作为可独立运行的脚本程序

为shell代码文件添加x权限,指定脚本路径即可运行

#chmod +x  /root/script.sh

# /root/script.sh

三、调试shell脚本

1.直接观察输出

2.开启调试模式:sh -x  脚本文件

3.插入echo断点

四、免交互

1.passwd改密免交互(--stdin)

#passwd --stdin username    //从键盘读入

#echo 1234567 | passwd --stdin username   //从echo命令给出,免交互

2.黑洞设备(/dev/null)

#echo 1234567 | passwd --stdin username &> /dev/null

原文地址:https://www.cnblogs.com/alphain/p/10827791.html