相关疑难解决方法(0)

使用“source file.sh”、“./file.sh”、“sh file.sh”、“../file.sh”执行shell脚本有什么区别?

看看代码:

#!/bin/bash
read -p "Eneter 1 for UID and 2 for LOGNAME" choice
if [ $choice -eq 1 ]
then
        read -p "Enter UID:  " uid
        logname=`cat /etc/passwd | grep $uid | cut -f1 -d:`
else
        read -p "Enter Logname:  " logname
fi
not=`ps -au$logname | grep -c bash`
echo  "The number of terminals opened by $logname are $not"
Run Code Online (Sandbox Code Playgroud)

此代码用于查找用户在同一台​​ PC 上打开的终端数量。现在有两个用户登录,比如 x 和 y。我目前以 y 身份登录,用户 x 中打开了 3 个终端。如果我使用上面提到的不同方式在 y 中执行此代码,结果是:

$ ./file.sh
The number of terminals opened …
Run Code Online (Sandbox Code Playgroud)

command-line bash scripts

14
推荐指数
1
解决办法
7942
查看次数

标签 统计

bash ×1

command-line ×1

scripts ×1