Set directory of files created by a shell script?

你离开我真会死。 提交于 2019-12-12 04:41:27

问题


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!


回答1:


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"


来源:https://stackoverflow.com/questions/3510353/set-directory-of-files-created-by-a-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!