shell - How to pass command line arguments from C program to the bash script? -


i have written 1 bash script , calling script c program. want pass arguments i.e. argv[1] , argv[2] script command line.

it depends on way script called. example, if using system can preformat string used invoke bash script system call adding command line arguments:

c

#include "stdio.h"  void main(int argc, char const *argv[]) {     if (argc == 2) {         char command[100] = {0};          sprintf(command, "./example.sh %s", argv[1]);         system(command);     } } 

bash

#!/bin/bash  echo $1 

as result

$ gcc example.c -o example && ./example hello! hello! 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -