我的.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'我想在我的Rakefile中执行'mfigpdf‘命令:
desc "convert all images to pdftex (or png)"
task :pdf do
sh "mfigpdf"
system "mfigpdf"
end但这些任务都没有奏效。我可以只复制rakefile中的命令,将它插入到一个shellscript文件中,但是我有重复的代码。
谢谢你的帮忙!
马蒂亚斯
发布于 2011-03-15 23:06:20
这里有三个问题:
source ~/.profile,或在存储别名的任何位置。shopt -s expand_aliases以在非交互式shell中启用别名。所以:
system %{
source ~/.profile
shopt -s expand_aliases
mfigpdf
}应该行得通。
但是,我建议使用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
}还有你的红宝石:
system 'source ~/.profile; mfigpdf'该函数的行为与交互式shell中的别名基本相同,并且在非交互式shell中更易于调用。
发布于 2011-03-13 18:14:17
sh mfigpdf将尝试运行具有该名称的外壳脚本,您必须改用sh -c mfigpdf。
为了启用别名扩展和加载~/.bashrc,您还必须使用-i标志强制bash进入“交互式外壳”模式。
sh "bash -ci 'mfigpdf'"您可以使用bash函数替换别名。函数也是以非交互模式展开的,因此您可以只使用~/.bashrc:
sh "bash -c '. ~/.bashrc ; mfigpdf'"发布于 2011-02-12 22:57:21
你必须源码你的.bashrc来加载别名,但是我认为ruby运行在sh上,不使用source命令,而是使用'.‘我相信这应该能行得通:
`. /path/to/.bashrc `
https://stackoverflow.com/questions/4978564
复制相似问题