M HYPE SPLASH
// general

Set parameters for Ubuntu's alias

By Emma Valentine

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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