小编use*_*100的帖子

使用变量来引用Bash中的另一个变量

x=1
c1=string1
c2=string2
c3=string3

echo $c1
string1
Run Code Online (Sandbox Code Playgroud)

我希望string1通过使用以下内容来输出: echo $(c($x))

所以稍后在脚本中我可以递增值x并输出string1,然后string2string3.

谁能指出我正确的方向?

variables bash

24
推荐指数
1
解决办法
4万
查看次数

bash 查找最初在 su sudo 之前启动脚本的用户

我有一个 bash shell 脚本,必须以 root 身份运行。如果用户启动它,系统会要求他们输入 root 密码,并且脚本会在子 shell 中重新运行。./$0 &

假设名为“John”的用户启动该脚本。在他提供 root 密码后,脚本将以 root 身份重新运行,但我如何才能知道谁最初从脚本本身启动了该脚本(John)?目前,我正在使用原始启动器转储一个文件,稍后我可以参考该文件,但这很丑陋。

我考虑的其他选项是使用进程列表,但同样,必须有一个更优雅的解决方案。

GNU bash,版本 4.2.45(2)-release (x86_64-slackware-linux-gnu)

linux bash shell sudo su

0
推荐指数
1
解决办法
1892
查看次数

标签 统计

bash ×2

linux ×1

shell ×1

su ×1

sudo ×1

variables ×1