我的.bashrc中有以下命令:
alias mfigpdf='for FIG in *.fig; do fig2dev -L pdftex "$FIG" "${FIG%.*}.pdftex"; done;
for FIG in *.fig; do fig2dev -L pstex_t -p "${FIG%.*}.pdftex" "$FIG" "${FIG%.*}.pdftex_t"; done'
Run Code Online (Sandbox Code Playgroud)
我想在我的Rakefile中执行'mfigpdf'命令:
desc "convert all images to pdftex (or png)"
task :pdf do
sh "mfigpdf"
system "mfigpdf"
end
Run Code Online (Sandbox Code Playgroud)
但这些任务都没有奏效.我可以在rakefile中复制命令,将它插入一个shellscript文件中,但是我有重复的代码.
谢谢你的帮助!
马蒂亚斯
这里有三个问题:
source ~/.profile或在子shell中存储别名的任何位置.shopt -s expand_aliases以在非交互式shell中启用别名.所以:
system %{
source ~/.profile
shopt -s expand_aliases
mfigpdf
}
Run Code Online (Sandbox Code Playgroud)
应该管用.
但是,我建议使用bash函数而不是别名.所以你的bash将是:
function mfigpdf() {
for FIG in *.fig; do
fig2dev -L pdftex "$FIG" "${FIG%.*}.pdftex"
done
for FIG in *.fig; do
fig2dev -L pstex_t -p "${FIG%.*}.pdftex" "$FIG" "${FIG%.*}.pdftex_t"
done
}
Run Code Online (Sandbox Code Playgroud)
还有你的红宝石:
system 'source ~/.profile; mfigpdf'
Run Code Online (Sandbox Code Playgroud)
该函数的行为与交互式shell中的别名基本相同,并且在非交互式shell中更容易调用.
您必须获取 .bashrc 来加载该别名,但我认为 ruby 在 sh 上运行,它不使用 source 命令,而是使用“.”。命令。我相信这应该有效:
`. /path/to/.bashrc`