When running the command
cmake ../../ -DCMAKE_C_FLAGS="-DFOO -DBAR ${CMAKE_C_FLAGS}"
in bash, it works fine.
When passing through a script, it fails:
./myscript "-DFOO -DBAR"
cmake ../../ -DCMAKE_C_FLAGS="-DFOO -DBAR ${CMAKE_C_FLAGS}"
Parse error in command line argument: -DBAR
myscript:
#!/bin/bash
cmake_options='-DCMAKE_C_FLAGS="'$1' ${CMAKE_C_FLAGS}"'
echo "cmake ../../ "$cmake_options
cmake ../../ $cmake_options
I know it must be related to escaping characters somehow so I tried all I could (double/single quotes, backquotes, escaping backslashes, using $() etc.), but I couldn't find the fix...
I'm not a linux expert, could someone help me please?
PS: I'm working on cygwin but I tested on a regular Linux as well and the behaviour is the same.
EDIT:
@Assere as described, I already tried many things and changing from $1 to "$1" doesn't fix the issue. What I mean by "bash" is directly in the command prompt while what I mean by "sh" is the "myscript.sh" file. I do have a #!/bin/bash, I just didn't know it was called a shebang. I also tryed quoting $cmake_options, to no results.