Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

linux - How can I configure bash to handle CRLF shell scripts?

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

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Perhaps like this?

dos2unix < script.sh|bash -s

EDIT: 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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...