Bash (Bash)、Z shell (zsh)、Fish (Fish)等shell语言和上面的脚本语言之间有什么区别,使它们更适合于shell?
在使用命令行时,shell语言似乎要容易得多。例如,对我来说,使用bash比在IPython中使用shell配置文件要流畅得多,尽管报告与此相反。我想大多数人都会同意我的观点,在Python中进行大部分中型到大型的编程比在Bash中更容易。我使用Python作为我最熟悉的语言。Perl和Ruby也是如此。
我试着阐明原因,但我不能,除了假设两者对字符串的不同处理与此有关。
提出这个问题的原因是我希望开发一种两者都可用的语言。如果你知道这样的语言,也请贴出来。
正如s .洛特所解释的,这个问题需要一些澄清。我问的是shell语言和脚本语言的特性。因此,比较不是关于各种交互(REPL)环境的特征,如历史记录和命令行替换。这个问题的另一种表达方式是:
适合于复杂系统设计的编程语言是否能够同时表达可以访问文件系统或控制作业的有用的一行程序?一种编程语言能有效地扩展和缩小吗?
你在回避这个问题。并不是每个人都认为shell语言更好。首先,_为什么不呢
Not long ago a friend asked me how to recursively search his PHP scripts for a string. He had a lot of big binary files and templates in those directories that could have really bogged down a plain grep. I couldn't think of a way to use grep to make this happen, so I figured using find and grep together would be my best bet.
find . -name "*.php" -exec grep 'search_string' {} \; -print
Here's the above file search reworked in Ruby:
Dir['**/*.php'].each do |path|
File.open( path ) do |f|
f.grep( /search_string/ ) do |line|
puts path, ':', line
end
end
end
Your first reaction may be, "Well, that's quite a bit wordier than the original." And I just have to shrug and let it be. "It's a lot easier to extend," I say. And it works across platforms.