Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k 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 OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...