开发者

Shell Scripting and other languages [closed]

开发者_StackOverflow It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I am interested in having opinion of you all on , How competitively strong is Shell Scripting compare to other scripting languages?

for example what kind of benefits does Shell scripting offers you over python or perl or ruby or R etc...

It would be fun to know from Shell Scripting geeks the advantages of Shell Scripting ... :)

No offences, I am a newbie in shell scripting and want to know the practical advantages of shell over other scripting languages..

Thank you in advance


Strengths of shells:

  • pipelines, filters and redirection to easily utilise the combined power of other programs/utilities
  • easy display and change of environment variables exported to - and OS limits affecting - programs you invoke
  • powerful and programmable command completion that's not only aware of built-in commands, but also directories, files and other programs and their command-line options (at least in good shells - zsh, bash...)
  • job control functions to run multiple jobs in the background, wait on their completion
  • filename globbing allows easy operations on sets of matching files
  • very terse/concise and reasonably powerful ad-hoc adjustments to environment variables (splitting them into words, removing/substituting substrings, taking the head or tail of directory paths...) that are unfortunately often hard to remember if you spend most of your time on things other than shell scripting...

What shells don't tend to be so great at is:

  • calling library routines written in other languages (though many can be compiled into utility programs)
  • user-defined structured data types and containers (hash tables, linked lists, trees)
  • type safety
  • performance


Shell scripts are really good at invoking programs. They also shine at redirecting stdin, stdout, and stderr for these in lots of ways and are pretty good at reacting to error codes returned by programs called. Function definitions are typically quite usable, if you are happy with using $1 etc. for the parameters.

Nothing other languages couldn't do, but the syntax is simply optimized to make these things super-simple.

While shell scripts (especially for shells that are properly scriptable, such as bash or zsh, certainly not csh or tcsh) do provide lots of other useful stuff and allow writing just about anything (a student I knew thought the numerics assignment was simply too easy for him, so he wrote his code as a bash script … working fine, of course), the syntax is simply not optimized for that and you typically have to write strange line noise to even increase n by 1.

In summary, I'd use shell scripts for anything that is more than maybe 80% calling external programs, and something else (typically ruby) for any scripting task that involves more logic and “classical programming.”


In my opinion, the pipes and filters system in shell scripting lets you write useful one-liners for the shell very easily. Usually you will also have a lot of short ways of interacting with typical shell tasks, e.g checking for file existence, iterating over files, etc. In more versatile scripting languages you might need more code for these tasks. However, you can do a lot more in other languages, e.g GUI-Programming, you get proper object orientation, inheritance, etc. IMO it's two tools for different aspects that have some use cases in common. Shell scripting languages will allow for automation of shell tasks or small script for direct interaction with files, sockets, processes, etc. Scripting languages are more versatile or specialized on different things (like R being specialized on computation and representation of statistical problems).


All shells are different, and so this must be taken with a pinch of salt, but there's not much difference between some of the better shell scripting environments and some of the languages you mention, such as perl and ruby. Especially when it comes to writing batch scripts.

However for day-to-day repl usage, a shell envronment will be more closely coupled to your file system, including linking you to a location in the file system. This will be the main advantage.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜