是否可以与其他用户一起使用 find 命令运行 bash 脚本查找



我正在尝试在目录中找到所有bash脚本,然后我想与另一个用户一起运行所有这些脚本。在 bash 文件中,我正在使用一个命令,该命令只能在其他用户下使用。

我尝试了这些命令:

    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 脚本中为我自己的命令找到"找不到命令"。

感谢您的回答,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

最新更新