如何配置bash处理CRLF shell脚本? [英] How can I configure bash to handle CRLF shell scripts?

查看:128
本文介绍了如何配置bash处理CRLF shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行恰好使用Windows/CRLF行尾的bash脚本.

I want to execute bash scripts that happen to use Windows/CRLF line endings.

我知道tofrodos软件包以及如何fromdos文件,但是如果可能的话,我希望在不做任何修改的情况下运行它们.

I know of the tofrodos package, and how to fromdos files, but if possible, I'd like to run them without any modification.

是否存在一个环境变量,将迫使bash处理CRLF?

Is there an environment variable that will force bash to handle CRLF?

推荐答案

也许是这样吗?

dos2unix < script.sh|bash -s

如注释中所指出的,这是更好的选择,因为它允许脚本通过运行dos2unix从stdin读取,而不是在子shell中进行bash操作:

As pointed out in the comments this is the better option, since it allows the script to read from stdin by running dos2unix and not bash in a subshell:

bash <(dos2unix < script.sh)

这篇关于如何配置bash处理CRLF shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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