我试图在目录中找到所有的bash脚本,然后我想与另一个用户一起运行所有的bash脚本。在bash文件中,我使用的命令仅在otherUser下可用。
我尝试了以下命令:
sudo -H -u otherUser find . -maxdepth 3 -type f -name '*myBashFile' -execdir {} \;
find . -maxdepth 3 -type f -name sudo -H -u otherUser '*myBashFile' -execdir {} \;
sudo -H -u otherUser bash -c 'find . -maxdepth 3 -type f -executable -name '*myBashFile' -execdir {} \;'
在bash脚本中,我总是为自己的命令找到“找不到命令”。
答案 0 :(得分:0)
感谢答案,PATH是关键,这是有效的最终代码:
#!/usr/bin/env bash
export PATH=$PATH:/path/of/the/command/
echo otherUserPassword | su -c 'find . -maxdepth 3 -type f -executable -name '*myBashFile' -execdir {} \;' otherUser