Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要检查另一个用户的主目录中的目录。通常我会 sudo 但这会分叉另一个进程,我也会失去我的环境。
例如,我有:
if [[ -d "/home/otheruser/svn" ]]; then echo "SVN exists" else echo "SVN does not exist" fi
我需要测试条件以 root 权限运行。
if sudo test -d "/home/otheruser/svn"; then
您需要在子外壳下运行它。例子:
if sudo bash -c '[[ -d "/home/otheruser/svn" ]]' then echo "SVN exists" else echo "SVN does not exist" fi