linux查看当前shell的方法

这篇文章主要对比一下 source 命令执行shell文件和 ./ping.sh 这种方式执行shell文件的区别。

1. source   ping.sh 这个是在当前的shell 中执行 ping.sh 里面的内容的。(source 和 . 是相同的,It has a synonym in . (period)

怎么查看当前的shell呢?

$$ 这个会输出当前shell的pid, echo $SHELL 这个变量直接输出当前shell ,我们这里是“/bin/bash”

#!/bin/bash
# 1、ping -c1 -w1 中-c1是指ping的次数,-w是指执行的最后期限,也就是执行的时间,单位为秒
# 2、&>/dev/null 是指标准输出和错误输出都输出到/dev/null上,而不在界面上显示;
# 后面的&&和|| 是与和或得意思,如a&&b||c ,表示a为真,则执行b;否则执行c

for I in `seq 1 254`; do
    ping  -c1 -w1 192.168.123.$I &>/dev/null && echo "192.168.123.$I is up" ||      echo "$I down"
done

  

这个ping.sh在当前的shell中执行的,相当于 ping 命令是一条一条输入到当前的shell 中的。

参考: 

source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in . (period).

Syntax

. filename [arguments]

source filename [arguments]

 ------------------------------------------------------------------------------------------------------------------------------

2.  ./ping.sh 执行

 

原文地址:https://www.cnblogs.com/oxspirt/p/9804269.html