Call bash aliases in rake

I have the following command in my .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'

And I want to execute the mfigpdf command in my Rakefile:

desc "convert all images to pdftex (or png)"
task :pdf do
  sh "mfigpdf"
  system "mfigpdf"
end

But none of these tasks work. I could just copy the command into rakefile to paste it into the shellscript file, but I have duplicate code.

Thank you for your help!

Matthias

+5
source share
3 answers

There are three problems here:

  • You need, source ~/.profileor wherever your aliases are stored, in a subshell.
  • You need to call shopt -s expand_aliasesto enable aliases in a non-interactive shell.
  • . ( - expand_aliases , . . .)

:

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'

, , .

+4

sh mfigpdf script , sh -c mfigpdf.

bash " " -i, ~/.bashrc.

sh "bash -ci 'mfigpdf'"

bash. , ~/.bashrc:

sh "bash -c '. ~/.bashrc ; mfigpdf'"
+3

You must specify your .bashrc to load these aliases, but I think ruby ​​runs on sh, which does not use the source command, but '.' command.I believe this should work:

`. /path/to/.bashrc `

+1
source

All Articles