小编use*_*657的帖子

以 root 身份调用 bash 函数但给出“意外的文件结尾”

为什么最后一个示例会抛出错误,而其他示例却可以工作?在任何情况下都会调用 Bash。

#!/bin/bash

function hello {
    echo "Hello! user=$USER, uid=$UID, home=$HOME"; 
}

# Test that it works.
hello

# ok
bash -c "$(declare -f hello); hello"

# ok
sudo su $USER bash -c "$(declare -f hello); hello"

# error: bash: -c: line 1: syntax error: unexpected end of file
sudo -i -u $USER bash -c "$(declare -f hello); hello"
Run Code Online (Sandbox Code Playgroud)

bash sudo su

1
推荐指数
1
解决办法
353
查看次数

标签 统计

bash ×1

su ×1

sudo ×1