Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

58

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 output differently on settings of LANG etc.? how much extra load does this add on your process? Forking a binary results in a lot more load and requires more ...


37

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 ttyUSB0-3, then that list will be used in other places so it will get factored out to follow the single responsibility principle, then a customer will have a ...


29

Shells have specialized features for working with files and getting data from one program into another (assuming that data is text). For those tasks, shell scripts can be less cumbersome than a scripting language like Python. Shell scripting also has the advantage that the commands you use are basically the same commands you'd use from the command line -- ...


23

REPL: This is a procedure that just loops, accepts one command at a time, executing it, and printing the result. The three steps at each iteration of the loop are: Calling read to read the characters that make up a textual expression from the keyboard input buffer, and construct a data structure to represent it, Calling eval to evaluate the expression--...


18

The existing answers are also valid, but there's one reason that no one has mentioned yet: because it WILL be there. Any given *nix install is done with some set of optional packages which may or may not be loaded, and not all systems will have Python or Perl or Ruby. But if the system is expected to have any interactive capability at all, it will have ...


16

The same reason that the iPod, iPhone (any phone for that matter), and the iPad don't: the command line is not the primary channel of user interaction with the computer in Windows. It is in UNIX or GNU/Linux - so that's why they're more mature. Same argument why the linux GUI desktops were rubbish for so long compared to Windows (Mac OS kind of cheats here ...


16

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 udevadm itself is doing when invoke in "info" mode: https://github.com/gentoo/eudev/blob/master/src/udev/udevadm-info.c and make equiv calls as to those ...


13

Maybe I'm oversimplifying, but I think of it as a cultural thing: In Microsoft culture, developers focus on writing programs for their users. The programs are all GUI-based. In Unix culture, developers focus on writing programs for other developers. The programs are small and focused on doing a specific thing well.


13

From my personal experience developer working on an *nix system needs to know: shell variables (how to set/get + knowledge about special ones like PATH) shell redirection (capturing output of an program) pipes (extracting some information from log file is an excelent example) process control (ps, nice/renice, kill) file access rights (ls/chmod/chown/chattr) ...


11

According to Wikipedia, the sh program reused the syntax from ALGOL 68. Stephen Bourne carried into this shell some aspects of the ALGOL 68C compiler that he had been working on at Cambridge University. Notably he reused portions of ALGOL 68's "if ~ then ~ elif ~ else ~ fi", "case ~ in ~ esac" and "for ~ while ~ do ~ od" (using done instead of od) clauses ...


11

According to http://slashdot.org/story/01/02/06/2030205/David-Korn-Tells-All (question 11), UWIN was not originally open source (though that appears to have changed in the 11 years since that interview was published). Not being open source would have been a significant barrier to widespread adoption, especially considering a functionally equivalent open ...


11

From my experience with my numerous colleagues since I started to work, nobody wants to fake Unix knowledge: either they "know their way around the command line" or they simply say "no way!". Just ask if the candidate is willing to work on a Unix workstation and let him tell you how far he can go through bash. He will eventually name some commands; the most ...


10

Why do this? The *nix shells (and other OS shells, fwiw) are very deep and broad working environments. It's possible for somebody to spend years working there and use only a very small % of the shells' capacity. If you don't expect the person to a) shell program, or b) administer the system from the shell, then why does it matter? Anything that gets done ...


9

Note that there's no reason that Microsoft can be the only one to write a shell for Windows. The guys who write bash are different from the guys who write *nix kernels. You don't even need root privileges. I've compiled my own shells to use when I didn't like the one the sysadmin installed. If there was a true demand for a better Windows shell, someone ...


9

A significant portion of your question is answered here: Why are scripting languages (e.g. Perl, Python, Ruby) not suitable as shell languages? Here's an excerpt from my answer to that question: There are a couple of differences that I can think of; just thoughtstreaming here, in no particular order: Python & Co. are designed to be good at ...


9

Technically, it's correct to say that a shell is an instance of a REPL. However, it isn't a matter of program definition as it is one of common usage scenarios. Bash, for example, is written in C, but it could well have been written in Python. At that point, if you talk about program features and abilities, would it be correct to say that Bash is a shell ...


9

Convenience of syntax, mostly. In python, running a process requires subprocess.call(...); renaming a file shutil.move(), etc. Bash syntax is much more direct for those tasks. Yes, Python is a great language, but the explicit syntax to execute (for bash) simple tasks is going to get in the way of doing day-to-day work real fast.


8

If you new to subversion I would suggestion skipping SVN and moving straight to Git (or Mercurial if you what). Git (and other distributed version control systems) are designed to work a lot better locally and for the most part have everything you would need from something like subversion. If you do go with git I would highly suggest you learn the command ...


8

$ is the default prompt prefix for a non-escalated bourn or sh shell on most *nix systems. It signifies that the code exemplified should be executed using one of those associated shells. zsh and csh have % as a prefix. The fish shell uses >. Putting the prefix is simply a quick way to let the reader know what shell the command is destined for.


7

Because there has never been enough call for one, I guess. Windows Scripting Host has been installed as standard since Windows 98 (I assume it was around before that); VBScript was very capable; or you could easily write a command-line tool, which had access to the whole Windows API. Powershell, put simply, is just another step in the same direction. COM ...


7

In bash, you can write mv img_{0..5} imgs/ which is expanded by the shell to mv img_0 img_1 img_2 img_3 img_4 img_5 imgs/ You can also use a character class: mv img_[0-5] imgs/ which would only work for those files that already exist and match the expression, while the former expands to all the possibilities even if the files do not exist. The curlies ...


7

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 how shell scripts are written, and sometimes how Python, perl or Ruby programs are written. People typically write in C for easy use of system libraries and ...


6

No. You find these "reversed" language constructs in many languages: { and }, /* and */ (* and *) :)


6

This is one of those questions that, ignoring conspiracy theories, probably doesn't have a single answer and is the kind of thing historians could argue about forever without ever finding a definitive answer. My impression is that the power of the shell is not immediately obvious. I started in on programming in Windows 3.1 and there was very little use of ...


6

Because there is little need and much pain in developing a second parallel Windows toolset. Shells are made powerful through the number and power of helper programs on a GNU system, such as sed, find, xargs et al. Re-implementing these tools is a lot of work, and just building a POSIX compliance layer on top of Windows has proven much easier. Cygwin is such ...


6

Possible Uses Fast Prototyping You could do this with Groovy or others, so that's not a very strong point, but as CRaSH gives you code-level access to the JVM and the processes it runs, it may come in handy to just keep a JVM running and experiment with small code snippets (for instance, using it as a REPL to implement solutions to StackOverflow questions)....


6

This is really hard to answer, because a ton of information is missing: How did you measure those sizes? Do they include libraries required to run the interpreter? Do they include runtimes? What Python implementation are you talking about? There are four production-ready implementations of Python in current use (PyPy, IronPython, Jython, CPython), plus ...


6

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 terminal hardware. You have to do the state tracking somewhere, and it's best to not do it in hardware that needs to be as cheap as possible. Even in modern ...


5

Windows has design features that do not lend themselves to scripting. This is a result of making the graphical interface the primary mode of operation. Many tools do not have functional command line interfaces. Without a decent command line interface it is very difficult to generate a good shell. Often things that need to be scripted in Windows require ...


5

If you consider the Unix shells "decent", then there's been at least one shell for Windows that's been "decent" for decades. The Hamilton C shell is reasonably close to the Unix C shell (though note that the C shell has never had particularly huge market penetration on Unix). Quite a few people have also used JPSoft's various shells (4DOS, 4NT, now called ...


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