Unix外壳之间的可移植性 - 我在思考这个问题是否正确? [英] Portability between Unix shells - am I thinking about the issue correctly?

查看:101
本文介绍了Unix外壳之间的可移植性 - 我在思考这个问题是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我写的s​​hell脚本(主要是软件开发的实用程序或创建工具)我一般尽量避免赞成使用普通的旧SH便携的使用bash。不过最近我一直运行到越来越多的问题,其中有用的功能不可用,或行为实际上是在整个使用SH那么它使用bash的系统不太一致,因为SH化名为不同的炮弹...

据我了解,SH是最古老的Unix外壳和精心编写的sh脚本在理论上应该在pretty多的系统运行在那里...但它似乎也有大约9000不同的每一个主要的壳变种了。不使用bash作为你的脚本间preTER有效地限制你的脚本的便携性?当然,在OS X或pretty很多在任何Linux没有问题摆在那里,但对于BSD系统? Solaris和AIX,HP-UX?你做什么,如果你真的想要的一切运行?

我知道的bash可以安装在几乎任何操作系统,但它确实是所有相关的现代系统中的头等公民?它来到pre-安装?我只是不能肯定它是否是最好的避免或与具有最一致和便携整体体验的意图拥抱庆典。


解决方案

  

你会怎么做,如果你真的想要的一切运行?


您遵循 SH POSIX标准C $ C> (和你调用的工具),并希望目标OS这样做了。任何所谓的UNIX的现代产品必须遵循这一标准,并习惯(虽然不是普遍),标准的外壳将被称为 / bin / sh的。而BSD和Linux发行版倾向于在POSIX兼容瞄准为好。

Whenever I write shell scripts (mostly software development utilities or build tools) I've generally tried to avoid using bash in favor of using plain old sh for portability. However lately I've been running into more and more issues where useful features are not available, or behavior is actually less consistent across systems using sh then it is using bash, since sh is aliased to different shells...

As I understand it, sh is the oldest Unix shell and carefully written sh scripts should in theory run on pretty much any system out there... but it also seems there are about 9000 different variants of every major shell, too. Doesn't using bash as your script interpreter effectively limit your script's portability? Sure, no problems on OS X or pretty much any Linux out there, but what about the BSDs? Solaris, AIX, HP-UX? What do you do if you really want to run on everything?

I know bash can be installed on virtually any OS but it is really a first class citizen on all relevant modern systems? Does it come pre-installed? I'm just not really sure whether it's best to avoid or embrace bash with the intent of having the most consistent and portable overall experience.

解决方案

What do you do if you really want to run on everything?

You follow the POSIX standard for sh (and the tools you're calling) and hope that the target OS does so too. Any modern product called "UNIX" must follow this standard, and customarily (though not universally), the standard shell will be called /bin/sh. The BSDs and Linux distros tend to aim at POSIX compatibility as well.

这篇关于Unix外壳之间的可移植性 - 我在思考这个问题是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆