Skip to main content
deleted 2 characters in body
Source Link
Vojtech Trefny
  • 20.7k
  • 6
  • 33
  • 59

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know aboutany similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

So for your example you'll need to do something like

int main(int argc, char *argv[])  {

   if (argc != 2) {
      printf("Argument expected\n");
      return 1;
   }
   
   if (strcmp (argv[1], "funcA") == 0)
      funcA();
}

And then you can call it from shell like

$ ./a.out funcA
Congrats..!! This is function A...!!

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know about similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

So for your example you'll need to do something like

int main(int argc, char *argv[])  {

   if (argc != 2) {
      printf("Argument expected\n");
      return 1;
   }
   
   if (strcmp (argv[1], "funcA") == 0)
      funcA();
}

And then you can call it from shell like

$ ./a.out funcA
Congrats..!! This is function A...!!

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know any similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

So for your example you'll need to do something like

int main(int argc, char *argv[])  {

   if (argc != 2) {
      printf("Argument expected\n");
      return 1;
   }
   
   if (strcmp (argv[1], "funcA") == 0)
      funcA();
}

And then you can call it from shell like

$ ./a.out funcA
Congrats..!! This is function A...!!
added 364 characters in body
Source Link
Vojtech Trefny
  • 20.7k
  • 6
  • 33
  • 59

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know about similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

So for your example you'll need to do something like

int main(int argc, char *argv[])  {

   if (argc != 2) {
      printf("Argument expected\n");
      return 1;
   }
   
   if (strcmp (argv[1], "funcA") == 0)
      funcA();
}

And then you can call it from shell like

$ ./a.out funcA
Congrats..!! This is function A...!!

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know about similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know about similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.

So for your example you'll need to do something like

int main(int argc, char *argv[])  {

   if (argc != 2) {
      printf("Argument expected\n");
      return 1;
   }
   
   if (strcmp (argv[1], "funcA") == 0)
      funcA();
}

And then you can call it from shell like

$ ./a.out funcA
Congrats..!! This is function A...!!
Source Link
Vojtech Trefny
  • 20.7k
  • 6
  • 33
  • 59

It's not possible to call a function from a C binary/library directly from shell. Some languages support this (for example Python with ctypes) but I don't know about similar option for bash (or other shells).

You'll need to use command line options options and call the C program with an option/argument that tells your program to call a specific function.