Bash: 脚本调用 Gnome 终端导致子进程错误?

Bash: Script Calling Gnome Terminal Leads To Child Process Error?

我正在尝试让一个脚本打开一个新终端 window,然后在该终端中调用另一个脚本。

我遇到错误:

There was an error creating the child process for this terminal

我认为这与尝试 运行 子进程的调用脚本有关。

我已经在 gnome-terminal 中尝试了 --x 选项。它不工作。 我确定有一种方法可以告诉终端在新终端中执行命令。我似乎无法在任何地方的文档中找到它。

有人 运行 解决了这个问题吗?

参考问题代码:第57、58行:

sudo gnome-terminal -x --window --wait --tab --active --title="" --geometry=120X60 \
--working-directory="$code_directory"  --command "$file_path"

完整上下文中的脚本:

#!/bin/bash
# Runs last modified script in new Terminal window tab in dev qube.

# Global vars
qube_name='dev'
code_directory='/home/user/Documents/'
last_modified='' # Last modified file in code directory.
file_path='' # Full file path of last modified file.


# Gets the last modified file in the code directory.
get_filename(){
    cd "$code_directory"
     last_modified=$(ls -t | head -n1)
    echo "$last_modified"
}


# Returns full file path.
get_full_path(){
    # =filename
    export file_path="$code_directory"
    echo "$file_path"
}


# Stops script if last modified file is this one.
check_filename(){
    # =file path
    # Guard clause to prevent recursive call.
    if [ "" == 'run_last_modified.sh' ]; then
        msg='Last modified file is run_last_modified.sh.
            Stopping execution...'
        notify-send "$msg";echo "$msg"
        exit
    fi
    echo ""
}

# Makes file executable if it isn't already.
make_executable(){
    #=file_path
    msg="Making $file_path executable..."
    echo "$msg"
    sudo chmod +x ""
    echo ""
}

# Opens a new terminal window and runs the file.
run_in_terminal(){
    #=file_path
    msg="Running  in $qube_name Terminal..."
    notify-send "$msg";echo "$msg"

    # -x option deprecated.  

    sudo gnome-terminal -x --window --wait --tab --active --title="" --geometry=120X60 \
    --working-directory="$code_directory"  --command "$file_path"

    # For dom0
    # qvm-run "$qube_name gnome-terminal -e $file_path"
}

run(){
    # Pipeline
    last_modified=$(get_filename)
    file_path=$(get_full_path)
    check_filename "$file_path"
    make_executable "$file_path" 
    run_in_terminal "$file_path"
}

run

################## TESTS #################
# Note to self: Comment out run ^^^ before running tests.

tests(){
    # get filename test.
    last_modified=$(get_filename)
    msg="Last modified: $last_modified"
    notify-send "$msg";echo "$msg"

    # get filepath test.
    file_path=$(get_full_path "$last_modified")
    msg="File path: $file_path"
    notify-send "$msg";echo "$msg"

    # Check filename test.
    # last_modified='run_last_modified.sh'
    # check_filename # Should stop execution.

    # Make executable tests.
    make_executable "$file_path"

}

# tests

-x--command 是 incorrect/obsolete 选项,试试这个:

sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
    --title="" --working-directory="$code_directory" -- "$file_path"

保持终端window打开:

sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
    --title="" --working-directory="$code_directory"\
    -- bash -c "$file_path; exec bash"