path_to_open=$(gfind ~/x/y/ | gshuf | ghead -n 1) && open "${path_to_open}"
我已经编写了一个我想在osx终端中使用的命令。它获取目录中的文件和文件夹路径列表,将它们混洗,然后获取shuffle之后txt第一行中的路径。
这是我到目前为止所得到的:[1]
gfind ~/x/y/ | gshuf | ghead -n 1
使用gfind ~/x/y/ | gshuf | ghead -n 1 > ~/Desktop/z.txt
我得到了这种格式/Users/me/x/y/some folder/some file.txt
的文件路径而不是将此文件或文件夹的路径写入.txt而不是将其打开,就像我只是双击它一样发现者。我怎样才能做到这一点?我认为open命令[2]是基于手册页中描述的正确命令[2],但我不确定如何使用它。我该怎么用?或者,如果这是错误的命令,我应该使用哪个命令?
[1]
我通过macports使用gnu coreutils这就是为什么在熟悉的命令名称前面有一个g
[2]
open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
Help: Open opens files from a shell.
By default, opens each file using the default application for that file.
If the file is in the form of a URL, the file will be opened as a URL.
Options:
-a Opens with the specified application.
-b Opens with the specified application bundle identifier.
-e Opens with TextEdit.
-t Opens with default text editor.
-f Reads input from standard input and opens with TextEdit.
-F --fresh Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
-R, --reveal Selects in the Finder instead of opening.
-W, --wait-apps Blocks until the used applications are closed (even if they were already running).
--args All remaining arguments are passed in argv to the application's main() function instead of opened.
-n, --new Open a new instance of the application even if one is already running.
-j, --hide Launches the app hidden.
-g, --background Does not bring the application to the foreground.
-h, --header Searches header file locations for headers matching the given filenames, and opens them.
答案 0 :(得分:0)
要在Finder中打开结果中返回的文件夹,这应该有效:
open -a Finder `gfind ~/x/y/ | gshuf | ghead -n 1`
答案 1 :(得分:0)
这对我有用:
path_to_open = $(gfind~ / x / y / | gshuf | ghead -n 1)&amp;&amp;打开“$ {path_to_open}”