在新闻脚本中使用Bash 4功能是否安全? [英] Is it safe to use Bash 4 features in news scripts?

查看:85
本文介绍了在新闻脚本中使用Bash 4功能是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bash4提供了一些不错的功能,例如globstar,关联数组,内置的mapfile等.

Bash4 offers some nice features like globstar, associative arrays, the mapfile builtin etc.

如果我使用这些功能,是否会大大降低脚本的可移植性?坚持Bash 3更安全吗?

Will it greatly decrease the portability of my scripts if I make use of these features? Is it safer to stick to Bash 3?

推荐答案

取决于您想要的便携性.

Depends on how portable you want to be.

由于Bash 4使用GPLv3,因此Apple不在Mac OS X上发布Bash 4.当然,用户可以根据需要自己安装它,但是大多数用户不会安装它.

Apple does not ship Bash 4 on Mac OS X since Bash 4 uses the GPLv3. Of course, users can install it themselves if they want, but most users won't have it.

如果您想移植到OS X,则可能不应该依赖Bash 4功能.但是,如果您不介意仅将它们移植到现代GNU/Linux发行版中,那么它们几乎都包括Bash 4,因此您最好也依赖它们.

If you want to be portable to OS X, you probably shouldn't rely on Bash 4 features. However, if you don't mind just being portable to modern GNU/Linux distros, then pretty much all of them include Bash 4, so you might as well rely on them.

此外,请记住,并非所有操作系统默认情况下甚至都提供bash.例如,默认情况下,OpenBSD附带了pdksh,您需要显式安装Bash. Debian发行了bash,但是/bin/sh是Dash,因此,如果要选择使用Bash特定功能,则需要显式使用#!/bin/bash.

Also, do recall that not all OS's even ship bash by default. For instance, OpenBSD ships pdksh by default, and you need to explicitly install Bash. Debian ships bash, but /bin/sh is Dash, so you need to explicitly use #!/bin/bash if you want to opt in to Bash specific features.

如果您真的想要可移植性,则应坚持使用POSIX/Single-Unix-Specification功能.但是,如果您需要的是在最新的GNU/Linux发行版(甚至是已经发行了几年的发行版)上运行,请使用/bin/bash并假定它是Bash 4应该没问题.

If you really want portability, you should stick to POSIX/Single-Unix-Specification features. However if all you need is to run on the latest GNU/Linux distros (and even ones a few years old), using /bin/bash and assuming it's Bash 4 should be fine.

这篇关于在新闻脚本中使用Bash 4功能是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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