【问题标题】:exo-open in a terminal script - program closes with the terminalexo-open 在终端脚本中 - 程序随终端关闭
【发布时间】:2012-04-06 12:04:08
【问题描述】:

我编写了一个简单的 bash 脚本,提示输入文件或目录路径并使用 exo-open 打开它,然后我将脚本分配给键盘快捷键,以便我可以 CTRL+SHIFT+ALT+O 随时通过终端提示打开任何内容:

还有脚本:

#!/bin/bash

# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/

# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename

# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"

# Open the file
exo-open "$filename"

echo "press enter to exit"
read enter

我的问题是生成的程序链接到终端,当终端关闭时它会带上程序 - 作为一个简单的解决方法,我最后有另一个用户提示来阻止终端关闭;有谁知道我怎样才能让终端关闭但保持结果程序打开?

我曾经/尝试过的一些想法:

  • exo-open 后运行 disown $!(无效)
  • 使用nohup(没用)
  • 从 PPID 运行 exo-open(不知道如何执行此操作)

在我的智慧尽头:-(

【问题讨论】:

  • disown 需要一个job-id,所以使用%1 而不是$!
  • 有趣,这给了我一个“无法执行默认终端仿真器。输入/输出错误。”警告。我刚刚使用setsid exo-open "$filename" 解决了它

标签: bash xfce


【解决方案1】:

Xfce 论坛成员 ToC

回答了这个问题

http://forum.xfce.org/viewtopic.php?pid=25670

原来你可以像这样使用setsid:

#!/bin/bash

# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/

# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename

# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"

# Open the file
setsid exo-open "$filename"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 2010-11-05
    • 2018-11-26
    • 2012-10-28
    • 2018-08-19
    • 1970-01-01
    • 2014-11-07
    相关资源
    最近更新 更多