我想用osx open命令打开一个文件,但是我拥有的是一个包含文件名(和路径)而不是文件名本身的变量。 我想:bash osx通过变量或管道打开文件
thisfile=./filename.extension
open $thisfile
和
thisfile=./filename.extension
printf $thisfile | open
和
printf ./filename.extension | open
但在所有这些尝试的我只是得到
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
Help: Open opens files from a shell.
...(全文: http://pastie.org/10074666)
我在做什么错?如何通过管道和变量打开文件?
EDIT /溶液:
我确实有空间(和括号),我在变量存储之前\
逃脱。事实证明,我不应该这样做,我应该通过变量使用open "${thisfile}"
不open $thisfile
所以对于文件
./foo - moo/zoo - boo (100)/poo (too).jpg
与开开这样
thisfile='./foo - moo/zoo - boo (100)/poo (too).jpg'
open "${thisfile}"
你的文件名是否有空格?你是否得到'无效选项:xxx'? – zmo 2015-04-05 09:12:05
您的第一个命令适用于OSX Yosemite。我不认为其他2将工作,因为'open'不读取它的'stdin',而是使用一个参数。 – 2015-04-05 09:17:05
如果你的文件名中有空格,使用'thisfile =“名称加空格”',并打开$ thisfile“' – 2015-04-05 09:39:52