Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run C functions in shell?

While learning C, I've recognized that you can see the manual of its functions within linux shell (I've been using BASH). For example:

man strlen
man crypt
man printf

I'd figured that maybe I could use those functions in shell scripting.

Is this true? How can I use those functions in shell script?

like image 582
Raynal Gobel Avatar asked May 22 '15 02:05

Raynal Gobel


2 Answers

You can't. Manpages are a relic of a time when there were no IDEs, and no Web to look things up in. You would write your code in an editor such as ed or vim or emacs, look up functions with man, compile with cc. The fact that man command looks up C functions does not mean you get to use those functions directly in a shell.

However, some of those functions also have an equivalent in *NIX: man 3 printf is a C function, but man 1 printf is a *NIX one.

like image 121
Amadan Avatar answered Oct 11 '22 20:10

Amadan


The short answer is, you can't use functions from the C library directly in the shell.

Look at the different man pages you get with the following commands:

man 1 printf
man 3 printf

The first one comes from section 1 (user commands), and the second one comes from section 3 (C library). While they serve a similar purpose, they are not the same. You can use the printf described in section 1 directly in the shell. Check out man 7 man to see a list of different sections.

like image 38
Markku K. Avatar answered Oct 11 '22 22:10

Markku K.