I'm trying to do simple c++ class generator in makefile (depending on given name), but it's really annoying when i don't know bash, and how those things work.
class:
@echo "Type class name: "; \
read CLASS_NAME; \
echo Creating class called $${CLASS_NAME}; \
echo "Class $${CLASS_NAME} {
int x;
int y;
};">./$${CLASS_NAME}.h
How can I make the last echo work? I don't know how to echo multiple lines.
The backslashes here are evaluated by make, not by the shell it invokes. (Similarly, make removes the newlines itself, instead of passing them to the shell).
The easiest thing to do here is to use a printf format string to insert your newlines rather than trying to make them literal:
class:
@echo "Type class name: "; \
read CLASS_NAME; \
echo "Creating class called $${CLASS_NAME}"; \
printf '%s\n' "Class $${CLASS_NAME} {" 'int x;' 'int y;' '};' >"./$${CLASS_NAME}.h"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With