使用bash进程替代sudo命令 [英] Using bash process substitution for a sudo command

查看:69
本文介绍了使用bash进程替代sudo命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用bash进程替代sudo命令.

I would like to use bash process substitution for a sudo command.

例如,这是一个对我有用的非sudo命令:

For example, here's a non-sudo command that works for me:

$ cat <(echo "installed.txt")
installed.txt

这是不起作用的命令的sudo版本:

And here's a sudo version of the command that does not work:

$ sudo cat <(echo "installed.txt")
cat: /dev/fd/63: Bad file descriptor

阅读sudo手册页后,在以root身份运行命令之前,sudo似乎关闭了除stdin/stdout/stderr文件描述符之外的所有文件.这使我认为bash在运行sudo命令之前正在创建描述符(并执行进程替换).

Reading the sudo man page, it seems that sudo closes all but the stdin/stdout/stderr file descriptors before running the command as root. This leads me to think that bash is creating the descriptor (and performing the process substitution) before running the sudo command.

我将root的shell更改为bash(而不是sh默认值).我已经测试了该命令以root身份登录时可以正常工作.它只能通过sudo命令不起作用.

I changed root's shell to bash (instead of sh default). I've tested that the command works fine when logged in as root. It only does not work via a sudo command.

什么是合适的技术来实现我在这里要做的事情?评估,报价,sudo标志,sudoers文件mod等?

What is the appropriate technique to achieve what I'm trying to do here? Eval, quoting, sudo flag, sudoers file mod, other?

推荐答案

尝试在您的shell中执行此操作:

Try doing this in your shell :

$ sudo bash -c 'cat <(echo "installed.txt for UID=$UID")'
installed.txt for UID=0

这篇关于使用bash进程替代sudo命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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