How do i run a bash script from a c program? Or rather is it possible to have all the features from bash programming in c?
How do i run a bash script from a c program? Or rather is it possible to have all the features from bash programming in c?
Well... I believe that BASh is written in C... so that should answer that.Originally Posted by harada
Sent from my iPadŽ
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
What are you trying to get bash to do which you can't do in C ?
From past experience, it's something like trying to find files, which is easily do-able in C.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
man system(3)
The usage of system() function is not recommended! The program will not be portable for different shells!Originally Posted by Binary
Instead of system() one can use fork()-execv(). Better and more portable!
popen is usable in that you can read the output of the executed command from your C code.
man popen
>instead of system() one can use fork()-execv(). Better and more portable!
Do we have a sys call that does the "cut" or "grep" operations?
Portability is a big issue when it comes to using it, but I have somehow gotten into the habit of using it very often..
In the middle of difficulty, lies opportunity
You don't have these system calls but instead you have a regex library. In my BSD system i have regex related functions. Use "man 3 -k regex" to list regex related manual pages.
You may not have those functions in Win32 environment. If you care about portability you can write your own "cut" or "grep" functions. They are not very difficult to implement (at least implementing cut and grep).
A word about regex. There are flavors - for example the difference between ksh & bash patterns, grep, egrep, and perl. The syntax of the regular expressions in those environments changes a lot. ... from least complex to most complex.
All this means is that the regex code you wrote may or may not support a regular expression you already have that works great -- elsewhere.