设置 shell 脚本创建的文件目录?

发布于 2024-09-14 19:45:19 字数 768 浏览 1 评论 0原文

编辑:必须重新标记它,因为,这是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨光如昨 2024-09-21 19:45:19

dirname 可用于获取文件的目录名称,或者您也可以使用与之前使用 / 进行扩展名相同的替换。

filedir="${no_ext%/*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex -output-directory "$filedir" "$no_ext.tex"

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.

filedir="${no_ext%/*}"
/usr/local/texlive/2009/bin/universal-darwin/pdflatex -output-directory "$filedir" "$no_ext.tex"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文