I use Apache Ant for automate build program from sources. build.xml
have exec
task with command lazbuild
which on my machine is not registered in path and needs to be called with some additional arguments. So I make alias in ~/.bashrc
with command:
alias lazbuild="/home/artem/fpcupdeluxe/lazarus/lazbuild --pcp='/home/artem/fpcupdeluxe/config_lazarus' --lazarusdir='/home/artem/fpcupdeluxe/lazarus'"
It works fine when I manually type lazbuild
in terminal, but when Ant start building it fails with error:
/home/artem/Projects/Lazarus/AutoScreenshot/build.xml:87: Execute failed: java.io.IOException: Cannot run program "lazbuild" (in directory "/home/artem/Projects/Lazarus/AutoScreenshot"): error=2, No file or directory.
I tried to create alias also in ~/.bash_profile
, ~/.profile
and new file aliases.sh
in /etc/profile.d/
directory, but without success.
Any ideas how to do this? Thanks.
Save yourself the trouble by turning your alias into a shell script. Create a ~/bin/lazbuild
containing
#!/bin/sh
/home/artem/fpcupdeluxe/lazarus/lazbuild --pcp='/home/artem/fpcupdeluxe/config_lazarus' --lazarusdir='/home/artem/fpcupdeluxe/lazarus' "$@"
run chmod +x ~/bin/lazbuild
, and add PATH="$PATH:$HOME/bin"
in your .bashrc
if you don't already have it. lazbuild
will now work as a bona fide command in all contexts.
If you really want to use the bash alias, you have to invoke bash, enable alias expansion, source your definition, and invoke your command in a separate parsing unit. This is a very bad practice:
<exec executable="bash">
<arg value="-c" />
<arg value="shopt -s expand_aliases; source ~/.bashrc; eval lazbuild" />
</exec>