BASH-在shell脚本上获取UID不起作用 [英] BASH - getting UID on shell script does not work

查看:90
本文介绍了BASH-在shell脚本上获取UID不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于bash的问题.

Hi I have a question about bash.

我是新手.

我制作了一个名为"test.sh"的文件,其内容为

I made a file named "test.sh" and its contents is

#!/bin/bash
set -x
echo $UID
echo "$UID"
echo "$(id -u)"

,结果为空白!什么都没有出现

and the result is blank!! nothing shows up

但是,当我在终端上键入"echo $ UID"时它显示"1011"

However, when i just type "echo $UID" on terminal it shows "1011"

我想念bash吗?

请帮助

已更新

bash版本是4.3.11,我键入"sh test.sh"来执行.

bash version is 4.3.11 and I typed "sh test.sh" to execute.

结果是

+ echo

+ echo

+ id -u
+ echo 1011
1011

谢谢!

推荐答案

$ UID 是未在 sh 下设置的Bash变量,这可能就是为什么它输出的原因空行.

$UID is a Bash variable that is not set under sh, that may be why it outputs blank lines.

尝试使用 bash test.sh 或使用 chmod u + x test.sh 使脚本可执行,然后将使用shebang中定义的程序(/bin/bash )

Try bash test.sh or make your script executable with chmod u+x test.sh, the program defined in shebang will then be used (/bin/bash)

这篇关于BASH-在shell脚本上获取UID不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆