How to run alias using bash -c from IDEA

bashcommand line

I'm trying to run a program defined in an alias (and the alias is defined in a source file)

alias myapp="/somepath/app -arg1 -arg2"

Then I go to IDEA and create an External Tool

Program: Bash
Arguments: -c "source /filewithalias.sh && myapp" 

Then when I run, I get the following message:

bash: myapp: command not found

EDIT:

I already tried prepending

shopt -s expand_aliases

To the command string but the result is still the same

Best Answer

The reason of your failure is that myapp is evaluated by bash at the time of the line evaluation, i.e. before its definition. I suggest you to avoid aliases for this purpose (I can't find any easy method with aliases).

Here is a simple method. If you don't have already one, create a personnal directory for all your binaries and shell scripts:

$ mkdir ~/bin

Add this new directory within your shell standard PATH:

PATH=${PATH}:~/bin
export PATH

Create a new shell script to fire your application with all the required arguments:

$ cd ~/bin
$ cat >myapp.sh <<eof
/somepath/app -arg1 -arg2
eof
$ make myapp

check that it is working from your actual environment:

$ myapp

Then call it from IDEA:

Program: myapp

check that it is working from within IDEA.