我有一个 shell 脚本,想要获取由 nautilus 对话框(或其他工具)选择的目录名称。例如:
#/usr/bin/bash
# choosing a path name
export my_directory=`pwd`
# open a nautilus dialog (1)
# which command may I do here to get the dirercory?
my_directory=`nautilus ${my_directory}`
# my directory now has the directory chosen by nautilus dialog
echo "my directory is ${my_directory}"
使用 ubuntu 原生组件可以实现吗?
答案1
一个相当直接的方法是使用zenity
例如
# basic syntax
zenity --file-selection --directory --filename="$PWD/"
一个简单的代码(来源:gnome zenity 帮助)
#!/bin/bash
DIR=`zenity --file-selection --directory --title="Select a File"`
case $? in
0)
echo "\"$DIR\" selected.";;
1)
echo "No file selected.";;
-1)
echo "An unexpected error has occurred.";;
esac
请zenity --help-file-selection
参阅其他选项。