How to call a C program in shell script?

前端 未结 3 677
心在旅途
心在旅途 2020-12-10 08:13

I have a simple question. I want to execute a C program in a shell script. How do I do that? Thanks for your help in advance.

3条回答
  •  萌比男神i
    2020-12-10 08:53

    cc hello_world.c #produces a.out
    ./a.out #run your program
    

    IMHO, your problem is the $PATH. Your current directory is not in PATH, so when you enter

    a.out
    

    your shell respond:

    -bash: a.out: command not found
    

    you should execute it as

    ./a.out
    

    (or add "." to your PATH, but this is not recommended.)

提交回复
热议问题