设置 shell 脚本创建的文件目录?
编辑:必须重新标记它,因为,这是一个 Sweave / R 问题,因为该脚本的问题是 Sweave 代码的输出目录。 R CMD Sweave 有相应的选项吗?
我有一个 shell 脚本,它从 .Rnw 文件创建 .tex 文件。该文件需要进一步处理,但脚本找不到它,因为它以某种方式自动生成到我的主目录中。
我需要在 .Rnw 文件的文件夹中生成 .tex 文件(因为所有其他信息都在那里)。请注意,.Rnw 文件通常是使用文件选择器选择的。
附带问题:是否有一个选择文件的选项,类似于Java中的JFileChooser,只能选择某些文件?
这是代码:
#!/bin/bash
myfile=$(/usr/bin/osascript << EOT
tell app "AppleScript Runner"
activate
return posix path of (choose file)
end
EOT)
if [ $? -eq 0 ]
then
R CMD Sweave $myfile
no_ext="${myfile%.*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex $no_ext.tex
open $no_ext.pdf
else
echo "User canceled"
fi
谢谢所有帮助完成这个初始脚本的人!
EDIT: had to retag this, because, it's rather a Sweave / R question since the problem of this script is the output directory of the Sweave Code. Is there a corresponding option for R CMD Sweave ?
I have a shell script that creates a .tex file from a .Rnw file. This file needs to be processed further, but is not found by the script because it's somehow automatically generated to my Home directory.
I need the .tex file to be generated in the folder of the .Rnw file (because all the other information is there). Note that the .Rnw file is what's usually selected with the file selector.
Side question: Is there an option for choose file, similar to JFileChooser in Java that enables only certain files for selection?
Here's the code:
#!/bin/bash
myfile=$(/usr/bin/osascript << EOT
tell app "AppleScript Runner"
activate
return posix path of (choose file)
end
EOT)
if [ $? -eq 0 ]
then
R CMD Sweave $myfile
no_ext="${myfile%.*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex $no_ext.tex
open $no_ext.pdf
else
echo "User canceled"
fi
Thx, to all those who helped with this initial script!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
dirname
可用于获取文件的目录名称,或者您也可以使用与之前使用/
进行扩展名相同的替换。dirname
can be used to get the directory name of a file, or you can use the same sort of substitution you did earlier for the extension with/
instead.