Use C in Shellscript

Asked

Viewed 61 times

0

In Shell we can use within the script other languages like awk and sed, I wonder if it would be possible to use the C language, and if yes, as.

  • 1

    See if this link helps you: https://www.unix.com/programming/122190-c-program-execute-shell-script.html

1 answer

1


Inside a shell script it is not possible to have native C code, like the case you mentioned from sed and of awk. I think it’s valid to think that in a shell script you can do everything you could do right at the terminal. For C, you need your own code and a compiler and therefore you can’t run it straight into . sh

However, you can make calls to an external C script if it is already compiled, for example

hello_world. c:

#include <stdio.h>

void main(){
    printf("hello world!\n");
}

hello sh.:

#!/bin/bash
./hello_world

after compiling the C (gcc hello_world.c -o hello_world), rotate the .sh and the exit will be

hello world!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.