1

I am working on a class project that requires a makefile and needs to parse input below as an example make myapp arg1 arg2 arg3 arg4....

So I create a myapp.py

import sys
program_name = sys.argv[0]
arguments = sys.argv[1:]
count = len(arguments)
for x in sys.argv:
    print("Argument: ", x)

I create a Makefile

all:
    alias testapp="python3 myapp.py"

Doing this it should allow me to write $ testapp arg1 arg2 arg3... If I manually input the alias statement into the terminal it works correctly, but when run in a Makefile, it doesn't work for me. Any ideas on a workaround for this? thank you in advance

khelwood
  • 55,782
  • 14
  • 81
  • 108
Jared
  • 75
  • 5

1 Answers1

3

This is not specific to make.

Aliases are only supported in interactive shells by default.

Also, any code run in a subprocess (i.e. any command you run which is not a shell builtin) will be unable to change anything in the parent process (aliases, variables, etc). So you can't change the behavior of your current shell with make, or a script, or any other external command (except if you cause the shell to cooperate, for example by using a shell builtin which evaluates code printed by a subprocess - eval and source are two common ways to make the shell cooperate).

A simple way to accomplish what you want is to make sure myapp.py has a valid shebang as its very first line

#!/usr/bin/env python3

then make the file executable;

chmod +x myapp.py

then create a symlink to it with the name you want to use in a directory which exists on your PATH. Assuming $HOME/bin already exists and is already on your PATH, simply

ln -s $(pwd)/myapp.py $HOME/bin/testapp

in the directory where you have myapp.py.

Aliases have some drawbacks; maybe prefer shell functions where you could have used an alias.

tripleee
  • 175,061
  • 34
  • 275
  • 318