我正在嘗試讓腳本打開一個新的終端視窗,然后在該終端中呼叫另一個腳本。
我收到錯誤:
為此終端創建子行程時出錯
我相信這與試圖運行子行程的呼叫腳本有關。
我已經在 gnome-terminal 中嘗試了 --x 選項。它不作業。我確信有一種方法可以告訴終端在新終端中執行命令。我似乎無法在任何地方的檔案中找到它。
有人遇到這個并有修復嗎?
參考問題代碼:第 57、58 行:
sudo gnome-terminal -x --window --wait --tab --active --title="$1" --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(){
# $1=filename
export file_path="$code_directory$1"
echo "$file_path"
}
# Stops script if last modified file is this one.
check_filename(){
# $1=file path
# Guard clause to prevent recursive call.
if [ "$1" == 'run_last_modified.sh' ]; then
msg='Last modified file is run_last_modified.sh.
Stopping execution...'
notify-send "$msg";echo "$msg"
exit
fi
echo "$1"
}
# Makes file executable if it isn't already.
make_executable(){
#$1=file_path
msg="Making $file_path executable..."
echo "$msg"
sudo chmod x "$1"
echo "$1"
}
# Opens a new terminal window and runs the file.
run_in_terminal(){
#$1=file_path
msg="Running $1 in $qube_name Terminal..."
notify-send "$msg";echo "$msg"
# -x option deprecated.
sudo gnome-terminal -x --window --wait --tab --active --title="$1" --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
uj5u.com熱心網友回復:
-x并且--command是不正確/過時的選項,試試這個:
sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
--title="$1" --working-directory="$code_directory" -- "$file_path"
要保持終端視窗打開:
sudo gnome-terminal --window --wait --tab --active --geometry=120X60 \
--title="$1" --working-directory="$code_directory"\
-- bash -c "$file_path; exec bash"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/413733.html
標籤:
