Why didn't Python (or Ruby, Perl, etc.) replace Bash into a system Shell?

Source: Internet
Author: User
Tags egrep
Associated question: www. zhihu. comquestion20244763 if the programming language can be used as a system Shell and is positively related to its popularity, why does Python not become a standard system Shell? Is it more economical to use Python (or other) as the system Shell than Bash or POSIXShell? Associated Issues: http://www.zhihu.com/question/20244763

If the programming language can be used as a system Shell and is positively related to its popularity, why does Python not become a standard system Shell?
Is it more economical to use Python (or other) as the system Shell than Bash or POSIX Shell? Reply content: Shell has many defects (tuo) trapped (xie. For example, in the simplest example, if the name of the downloaded file contains many spaces, it will be difficult to prepare bulk operations, such as archiving. The automatic parsing of Shell usually makes you miserable. And that is a feature, right? That is not a bug.

In fact, this is a typical problem that is not suitable for solving with Shell. You can find a tool without automatic parsing, such as any script language. Why Ruby? Of course, Ruby has irb.

Irb (main): 033: 0> dir = 'archives-dir'
Irb (main): 034: 0> dst = 'your-destination-directory'
Irb (main): 035: 0> num = 16
Irb (main): 036: 0> lines = 'LS-rt ~ /Downloads/| tail-n # {num} '. split ("\ n ")
Irb (main): 037: 0> lines. each {| l | print 'mv "# {l}" # {dir}/# {dst }'}

This is so simple. Actually, there are only two lines. I only write so many variables because I still have many files to interact. Then I only need to change the volume, then use the arrow to find the history, and press enter all the way.

But why cannot Shell be replaced? Because there are still a large number of interactive tasks that can be simply and unimagined when Shell is used.

Diff-u <(ls | sort) <(grep amazon mp3.url.txt | \
Awk-F'/''{print $ NF} '| sort) 2> & 1 | \
Egrep '^ \ + [^ +]' | sed-e's/^ \ +/'| \
Xargs-n 1./download. sh

Even so

Diff-u <(ls | sort) <(ssh-I ~ /My. key dove @ myhost grep amazon mp3.url.txt | \
Awk-F'/''{print $ NF} '| sort) 2> & 1 | \
Egrep '^ \ + [^ +]' | sed-e's/^ \ +/'| \
Xargs-n 1./download. sh

Therefore, Shell should be used to solve the problem.

By the way, why not use Python?

I really don't want to be alignment ...... ...... ......

Life is too short to use Python.

Slightly Add the advantages of Shell. It's something like Shell. After all, it's also an old comrade who has a long history and is tested by alcohol, therefore, it is not easy for users to determine the exact number of mathematical calculations in different versions...

@ Wolong and @ yegle both make sense, but I think everyone has ignored it, that is, a software Inertia(Or a habit ). Especially for Shell-based infrastructure software, once enabled for a while, many people will adopt such standards, so as long as it is not too bad, it will not change.

For example, when my teacher taught me how to use Linux, I used vi to edit files, so I didn't know what vim was for a long time. Later, I used the vi command. It was not a matter of having one letter missing, but I got used to it. We also know that there is no vi in Linux, at least debian does not. vim-tiny is installed by default, and the full version of vim can be installed. vi is always a link of vim. I don't know whether my teacher started to use vi in UNIX or I taught vi when I taught it, as a set of software inherited from UNIX, the format and style of commands are also a kind of inertia and should not be changed easily. There are many such examples in Linux, such as cc-> gcc, lex-> flex, yacc-> bison, all follow the UNIX habit.

In UNIX-like systems, too many scripts are written using Shell scripts, so this should not be changed easily. For example, if we have compiled some software or class libraries, we will. /configure is a script written in Shell (generated accurately. Open the first line of this file and you will see #! /Bin/shSuch a paragraph. We all know that sh and bash are different. As an old Shell, sh has basically been replaced by the successor bash in Linux, however, the autoconf scripts still inherit the old inertia of sh and are also designed to be compatible with other systems. For example, in FreeBSD, bash is not installed by default.

So it's not a good thing or a bad one, that is, everyone gets used to it. There's no big problem, and it's hard to change it for decades. The reason is very simple. History habits + no one does it.

I can't do shell in python. Do you know scsh? Scheme can be used as shell. Why is python not? To put it bluntly, I had to do a pysh job. After two weeks of compatibility with different terminal types, I had to give up. At that time, interaction, interpretation and execution, basic I/O, and pipelines had taken shape. I think it can be completely replaced. Let's take a look at how clojure calls shell:

(require '[me.raynes.conch :refer [programs with-programs let-programs] :as sh])user> (programs echo)#'user/echouser> (echo "Hi!")"Hi!\n"user> (programs cat)#'user/catuser> (cat {:in "hi"})"hi"user> (cat {:in ["hi" "there"]})"hi\nthere\n"
For complex logic, python is modular and easier to use than shell.

But for a single command, what is the feeling of using python, each command must call the http:// OS .xxx In addition, python functions are not separated by spaces like shell, but with parentheses, commas, and quotation marks. The screen is too beautiful for me to think about.

Therefore, the best solution is to coexist and directly use shell to write scripts in python. In fact, many linux releases come with python. It is okay to replace shell with python to write scripts. @ Yu Tiansheng said that "inertia" is very reasonable, but there are many people around me who have switched to zsh (including me) on others' recommendations after using bash for many years ), the switchover is completed in just a few days. After learning that the vi in the Debian system is just the alias of vim, there are a lot of people who have developed the habit of playing vim instead of vi. Therefore, what I think is special is not bash, but shell. The difference between shell and other scripting languages is very important.
The so-called "shell" must first be Operating System Interface(This is also the original meaning of shell), followed by a programming language. In the operating system's functions, file system and process management are two important parts. Therefore, shell emphasizes FileAnd Command, Which is not available in other script languages. Specifically, there are both semantic and syntactic methods.
The simplest method is to use vim to open file a. c and write it in shell:

vim a.c
Obviously, bash is more concise. Python, Ruby, and Perl are not necessary to replace Bash. Bash is a Domain-Specific Language, while Python is a General-purpose Programming Language, the purpose of the language itself is different, which is also the significance of the existence of DSL. For more information, see Wikipedia related entries.

The premise for us to discuss this issue is that in the * nix context, we should look for reasons from * nix's own development history, which makes it difficult to understand why Python will never replace it as a Shell.

The limitation of hardware conditions in the early stage of Unix determines * nix's design philosophy. The most important two aspects are: 1. A tool only does one thing and completes it well; 2. Tools exchange data through plain text. This design reduces the complexity of the system. Glue LanguageYou can build blocks to complete many complex tasks. Because it does not require complex data structure operations, Shell does not need to be a complete programming language like Python or Perl, and this condition has not changed yet.

Here I agree with @ yegel's point of view. As for @ Wolf's speech on Bash syntax, I believe that Bash syntax will not be completely changed for a long time in the future. In the * nix world, Shell implementation is not just Bash. portability is a very important factor. Most of the wonderful syntaxes mentioned by @ wolf are defined by POSIX, thanks to the existence of POSIX, we can enjoy the benefits of * nix.

In addition, languages with interactive modes may not always be used as shells. A necessary condition for Shell is to conform to * nix's design philosophy and become a glue language as a medium for communication between tools, at least implement PipeIs indispensable. Because:
BASH is used "Use"
Python uses" Editing"Python? Do you want to call (["ls", "path"]) once every time? Parentheses are not fun at all =. =
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.