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/opencv4Running 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.cppIt 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 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