Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

bash script

I have read through some tutorials on #!/bin/sh programming, but I am looking for something more specific and thought about asking the question here.
I want to be able to read a bash script through a c++ main, this script would allow compilation and execution of another module. Could somebody provide a brief example as to how this might be done?

Here is what I think should work, but it doesn't.

#!/bin/sh
echo "Inside the script"

##I want to pipe to a file in the current dir.

ls | myFile.cpp
N=$1
while test "$N" != "0"
do
g++ -c myFile.cpp
g++ -o my myFile.cpp
./my $N
N=$[N-1]
done

echo "compile and execution complete"


Thank you for taking the time to reply.

Comments

  • XfactorXfactor Member Posts: 343
    : I have read through some tutorials on #!/bin/sh programming, but I am looking for something more specific and thought about asking the question here.
    : I want to be able to read a bash script through a c++ main, this script would allow compilation and execution of another module. Could somebody provide a brief example as to how this might be done?
    :
    : Here is what I think should work, but it doesn't.
    :
    : #!/bin/sh
    : echo "Inside the script"
    :
    : ##I want to pipe to a file in the current dir.
    :
    : ls | myFile.cpp
    : N=$1
    : while test "$N" != "0"
    : do
    : g++ -c myFile.cpp
    : g++ -o my myFile.cpp
    : ./my $N
    : N=$[N-1]
    : done
    :
    : echo "compile and execution complete"
    :
    :
    : Thank you for taking the time to reply.
    :
    First off, to execute any command in a shell script, you need to use the `command` ( with the "backticks")
    Second, It looks to me like all you are wanting to do is compile and execute your program. Really a shell script isn't necessary. All you need is a make file. Thats what they are used for.

    Hope I helped out.

    X
  • Craz1Craz1 Member Posts: 4
    : : I have read through some tutorials on #!/bin/sh programming, but I am looking for something more specific and thought about asking the question here.
    : : I want to be able to read a bash script through a c++ main, this script would allow compilation and execution of another module. Could somebody provide a brief example as to how this might be done?
    : :
    : : Here is what I think should work, but it doesn't.
    : :
    : : #!/bin/sh
    : : echo "Inside the script"
    : :
    : : ##I want to pipe to a file in the current dir.
    : :
    : : ls | myFile.cpp
    : : N=$1
    : : while test "$N" != "0"
    : : do
    : : g++ -c myFile.cpp
    : : g++ -o my myFile.cpp
    : : ./my $N
    : : N=$[N-1]
    : : done
    : :
    : : echo "compile and execution complete"
    : :
    : :
    : : Thank you for taking the time to reply.
    : :
    : First off, to execute any command in a shell script, you need to use the `command` ( with the "backticks")
    : Second, It looks to me like all you are wanting to do is compile and execute your program. Really a shell script isn't necessary. All you need is a make file. Thats what they are used for.
    :
    : Hope I helped out.
    :
    : X
    :


    Here is a sample Makefile for ya:

    #
    # - makefile for 'MyApp' -
    # note: you have to use TAB's for the indents in a makefile...
    #
    all: MyFile

    myFile: MyFile.cpp
    g++ -Wall -o myFile MyFile.cpp
  • Andre YoungAndre Young USAMember Posts: 0

    _____ { http://forcoder.org } free ebooks and video tutorials about \ Python, Objective-C, PL/SQL, Ruby, Scratch, Swift, R, Visual Basic .NET, Java, Visual Basic, C#, Go, PHP, Assembly, Perl, C, Delphi, JavaScript, C++, MATLAB SAS, Hack, ML, Prolog, Alice, Logo, Fortran, Clojure, Scheme, Dart, Scala, VBScript, D, Ada, COBOL, Apex, Bash, ABAP, Lisp, Crystal, Erlang, FoxPro, Kotlin, F#, LabVIEW, Julia, Awk, Rust, Lua, Transact-SQL \

Sign In or Register to comment.