Set Parameters for Ubuntu's Alias

I have an example command as follows:

g++ main.cpp -o main -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4

Running the entire above command will create file main based on the second argument main after the parameter -o. I have reset it in file .zshrc as follows:

alias ocv='f(){ g++ "$@" -o built_$@ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4; unset -f f; }; f'

Now run the above command as follows:

ocv main.cpp

It will create a file called built_main.cpp. But I want it to generate the file main by removing the extension .cpp. How to do it?

1

1 Answer

For zsh you should use modifier :r on $@, see e.g. this.

So it would be

alias ocv='f(){ g++ "$@" -o built_$@:r -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -I/usr/local/include/opencv4; unset -f f; }; f'
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest