Bash (Bash)、Z shell (zsh)、Fish (Fish)等shell语言和上面的脚本语言之间有什么区别,使它们更适合于shell?
在使用命令行时,shell语言似乎要容易得多。例如,对我来说,使用bash比在IPython中使用shell配置文件要流畅得多,尽管报告与此相反。我想大多数人都会同意我的观点,在Python中进行大部分中型到大型的编程比在Bash中更容易。我使用Python作为我最熟悉的语言。Perl和Ruby也是如此。
我试着阐明原因,但我不能,除了假设两者对字符串的不同处理与此有关。
提出这个问题的原因是我希望开发一种两者都可用的语言。如果你知道这样的语言,也请贴出来。
正如s .洛特所解释的,这个问题需要一些澄清。我问的是shell语言和脚本语言的特性。因此,比较不是关于各种交互(REPL)环境的特征,如历史记录和命令行替换。这个问题的另一种表达方式是:
适合于复杂系统设计的编程语言是否能够同时表达可以访问文件系统或控制作业的有用的一行程序?一种编程语言能有效地扩展和缩小吗?
如果你知道这样的语言,也请贴出来。
Tcl就是这样一种语言。主要是因为它主要被设计为CAD程序的shell解释器。以下是一位铁杆Python程序员体会到Tcl为何被设计成这样的经历:我不敢相信我在称赞Tcl
对我来说,我已经编写并一直在使用并改进了Tcl shell(当然是用Tcl编写的),作为我在自制路由器上的主要Linux登录shell: Pure Tcl readline
总的来说,我喜欢Tcl的一些原因与它与传统shell的语法相似有关:
At its most basic, Tcl syntax is command argument argument.... There's nothing else. This is the same as Bash, C shell or even DOS shell.
A bareword is considered a string. This is again similar to traditional shells allowing you to write: open myfile.txt w+ instead of open "myfile.txt" "w+".
Because of the foundations of 1 and 2, Tcl ends up with very little extraneous syntax. You write code with less punctuation: puts Hello instead of printf("Hello");. When writing programs you don't feel the hurt so much, because you spend a lot of time thinking about what to write. When you use a shell to copy a file you don't think you just type and having to type ( and " and , and ) and ; again and again gets annoying very quickly.
*注:不是我;我是一个铁杆的Tcl程序员
如果你知道这样的语言,也请贴出来。
Tcl就是这样一种语言。主要是因为它主要被设计为CAD程序的shell解释器。以下是一位铁杆Python程序员体会到Tcl为何被设计成这样的经历:我不敢相信我在称赞Tcl
对我来说,我已经编写并一直在使用并改进了Tcl shell(当然是用Tcl编写的),作为我在自制路由器上的主要Linux登录shell: Pure Tcl readline
总的来说,我喜欢Tcl的一些原因与它与传统shell的语法相似有关:
At its most basic, Tcl syntax is command argument argument.... There's nothing else. This is the same as Bash, C shell or even DOS shell.
A bareword is considered a string. This is again similar to traditional shells allowing you to write: open myfile.txt w+ instead of open "myfile.txt" "w+".
Because of the foundations of 1 and 2, Tcl ends up with very little extraneous syntax. You write code with less punctuation: puts Hello instead of printf("Hello");. When writing programs you don't feel the hurt so much, because you spend a lot of time thinking about what to write. When you use a shell to copy a file you don't think you just type and having to type ( and " and , and ) and ; again and again gets annoying very quickly.
*注:不是我;我是一个铁杆的Tcl程序员
No.
不,脚本语言可能不适合shell。
问题在于宏语言和其他所有语言之间的二分法。
shell与其他遗留宏语言(如nroff和m4)属于一类。在这些处理器中,所有内容都是字符串,处理器定义了从输入字符串到输出字符串的映射。
在所有语言中,某些边界都是双向交叉的,但通常很清楚系统的类别是宏观的还是,嗯,我不知道有一个官方术语……我会说“一种真正的语言”。
当然,您可以用Ruby这样的语言输入所有的命令,它甚至可能是仅次于真正shell的次优选择,但它永远不会是宏语言。有太多的语法需要考虑。它需要太多的引号。
但是在开始使用宏语言编程时,宏语言也有它自己的问题,因为必须做出太多妥协才能摆脱所有语法。输入字符串时不带引号。需要重新引入各种神奇的方法来注入缺失的语法。我在nroff做过一次code-golf,就是为了与众不同。这很奇怪。宏语言中大型实现的源代码是可怕的。