[英]bash programming STDIN redirect
I want to get the home directory of a user of a unix system.我想获取 unix 系统用户的主目录。 Why doesn't the following work:
为什么以下不起作用:
# sudo su $offender -c "bash -s < <(echo echo \$HOME)"
sh: Syntax error: redirection unexpected
It works for me in Ubuntu and Fedora using sudo su $offender -c "echo \$HOME"
它适用于 Ubuntu 和 Fedora 使用
sudo su $offender -c "echo \$HOME"
You could also gouge it from your /etc/passwd file like so:您也可以像这样从 /etc/passwd 文件中获取它:
grep "^$offender" /etc/passwd | cut -d':' -f6
Don't really know why it doesn't work, but here's a way to get the home directory that does not involve spawning a shell as that user:真的不知道为什么它不起作用,但这是一种获取主目录的方法,它不涉及作为该用户生成 shell:
getent passwd "${offender:?No Offending Account Given}" | awk -F':' 'NR==1{print $6}'
The direct problem is that sh
does not recognize process substitution (the <(echo $HOME)
) notation, even when it is a link to bash
.直接的问题是
sh
不识别进程替换( <(echo $HOME)
)符号,即使它是指向bash
的链接。
It seems like a rather brute force way to get the information.这似乎是一种获取信息的蛮力方式。 Doesn't:
不会:
eval echo ~$offender
work for you?为你工作?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.