Skip to content
Snippets Groups Projects
compile-and-run.sh 342 B
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/sh
    
    usage () {
        echo compile-and-run [program.cpp]
        echo
        echo Compiles and executes a c++ program.
        echo The standard input and output is passed down to the program.
        echo The exit status is that of the compiler.
    }
    
    if [ x"$1" = "x" ]; then
        usage
        exit 0
    fi
    
    if g++ prog.cpp; then
       ./a.out
    else
       exit $?
    fi