Skip to main content
59 votes
Accepted

Is it a good idea to call shell commands from within C?

It's not particularly bad, but there are some caveats. how portable will your solution be? Will your chosen binary operate the same everywhere, output the results in the same format etc.? Will it ...
Brian Agnew's user avatar
  • 4,686
37 votes

Is it a good idea to call shell commands from within C?

It takes extreme care to guard against injection vulnerabilities once you've introduced a potential vector. It's in the forefront of your mind now, but later you may need the ability to select ...
Karl Bielefeldt's user avatar
16 votes

Is it a good idea to call shell commands from within C?

In your specific case, where you want to invoke udevadm, I'd suspect you could pull in udev as a library and make the appropriate function calls as an alternative? e.g., you could take a look at what ...
Adam Krouskop's user avatar
8 votes

Is it a good idea to call shell commands from within C?

Your question seemed to call for a forest answer, and the answers here seem like tree answers, so I thought I'd give you a forest answer. This is very rarely how C programs are written. It is always ...
Omnifarious's user avatar
6 votes

Shell Script Design Patteren: Source a library file VS Call different files?

First piece of advice is to echo Stefano Borini: "don't." Some languages offer good support for core software engineering concepts without the need of supporting 1970's sh syntax. Prefer ...
J_H's user avatar
  • 7,320
6 votes
Accepted

When to malloc and free?

I'm not going to debug your code, there's not enough context to do this anyway, but I'm going to show you an idiom that you will probably find easier to use correctly. As a bonus, it will also be ...
5gon12eder's user avatar
  • 7,206
6 votes
Accepted

git clone vs cp -R

Copying copies the working copy, any untracked files, and any local configuration along with the actual repository. Cloning doesn't, but it sets up the origin remote with a tracking branch. Use ...
Sebastian Redl's user avatar
6 votes

Why not program our video text terminals/terminal emulators to use something JSON or XML on the backend instead of ANSI escape sequences?

Your question is sort of like saying assembly is difficult to work with, so computers should use higher level languages instead. The ANSI format is the right level of abstraction for working with ...
Karl Bielefeldt's user avatar
4 votes
Accepted

Are parser generators useful for parsing a shell language?

Context-free grammars are grammars where the left side of every production rule is a non terminal term (aka an abstract grammar construct) whereas the right side can be a mix of terminals (aka tokens ...
Christophe's user avatar
  • 78.3k
4 votes
Accepted

Why not program our video text terminals/terminal emulators to use something JSON or XML on the backend instead of ANSI escape sequences?

There is a simple reason. When you are typing you can only input a character at a time. Something that is processing typed text has to deal with what in effect is invalid markup, half a json blob or ...
Ewan's user avatar
  • 77k
3 votes
Accepted

How to call more than one program from a single process in an efficient way?

This sounds similar to how CGI worked in the earliest days of the internet. Each web request would launch a process to return the contents of the page. The performance eventually became poor and an ...
Bill Door's user avatar
  • 1,080
3 votes

git clone vs cp -R

This is not strictly an answer to you question, but if you want to start a new project, do you really want to copy all the history, branches, etc from the old project? If you just want a working ...
axl's user avatar
  • 1,217
3 votes
Accepted

Unit testing C code?

Your certainly on the right track. For my projects I use: "check" to unit test all method (including as many code paths as I can - have time for). This runs super fast and gives me confidence that ...
Wayne Booth's user avatar
3 votes

algorithm for shell language interpreter to find if a char is between quotes

do you agree this is a good way of solving the problem? No. When you parse a shell command line, you work your way through the string, and so at any point you should already know whether you are ...
Sebastian Redl's user avatar
2 votes

Recommended guidelines for declaring bash/sh variables

A few tips. Local variables are declare local and initializated to null if strings or 0 if number if you develop in bash use bash. (+=, for arg;do done;...) Use always builtin [[ notnumber ]] or (( ...
more2000's user avatar
1 vote

Delaying pods creation or recreating pods until tasks in other pods are completed

Kubernetes does not model such dependencies between resources. All your pods should be loosely coupled. A pod that has unmet dependencies might not report as ready or healthy, but is running just fine....
amon's user avatar
  • 135k
1 vote
Accepted

Local Path on Linux

According to this answer: https://unix.stackexchange.com/questions/316765/which-distributions-have-home-local-bin-in-path There is a: ~/.local/bin/ Executables that shall appear in the user's $PATH ...
Helena's user avatar
  • 817
1 vote
Accepted

Streamlining development process of Linux C++ CLI app

Thanks to GrandmasterB, I realized that for C++ projects, it is ordinary to add Makefile to make things even easier and streamlined. Makefile This is quite new to me. I like the way things get ...
Vlastimil Burián's user avatar
1 vote

How to call more than one program from a single process in an efficient way?

Running programs in processes is operating system specific. The only standard way to do that otherwise is by using system which is probably not suitable. You might use some C++ frameworks (like POCO ...
Basile Starynkevitch's user avatar
1 vote
Accepted

algorithm for shell language interpreter to find if a char is between quotes

In principle, you could use something like your isBetweenQuotes function, but you're (probably) better served by a more structured way of parsing arguments pipelines. However, something like the ...
Vatine's user avatar
  • 4,269
1 vote
Accepted

For loop and recursion for a new shell in C

I think that between compound lists (which involve parenthesized expressions) and various operators (like |, && and ||, ...) the shell grammar is fundamentally recursive in nature, so yes, you ...
Erik Eidt's user avatar
  • 34.2k
1 vote

Executing scripts in parallel based on dependency tree

Probably not the best way to do it.. But if the dependency tree is a DAG, we can use a topological sort to find an ordering that will make sense, and then we can use bash to call the scripts. For ...
Harish Ganesan's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible