Let's say that I write some commands in a file let's say cmake although it doesn't need to be cmake run writing some commands in a text file. example

filename: cmake_command

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ../prject-src/ && make && make install

let's for simplicity say that the cmake_command file is located in a folder where if you run the command as is, things will start building.

I tried this command

for i in $(cat cmake_command); do echo $i; done

as a test but instead of printing out 1 whole line, it splits on each white space so I get a list of individual strings.

How could I reorganize this command to work so instead of getting

make && make install

i'd get this output

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ../prject-src/ && make && make install

closed as unclear what you're asking by G-Man, Anthon, Archemar, Stephen Kitt, roaima Dec 21 '15 at 10:23

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    I'm not sure what you're trying to do. Are you trying to print the cmake_command file line-by-line? If so, what is wrong with just cat cmake_command? – Joseph R. Dec 21 '15 at 1:09
  • have all command one line at a time, then run bash -e command_file, -e flag will ensure exit on first error. – Archemar Dec 21 '15 at 7:40

The most easy way would be:

while read i; do echo "$i"; done < cmake_command
  • Will this produce output that is different from cat cmake_command? – Joseph R. Dec 21 '15 at 1:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.