/bin/bash^M: bad interpreter: No such file or directory


While running some sh scripts i faced the below issue.

[biadmin@illinxxxx scripts]$ ./nftp_vals.sh
./nftp_vals.sh: ./nftcontroller.sh: /bin/bash^M: bad interpreter: No such file or directory
./nftp_vals.sh: ./throughput_and_latency.sh: /bin/bash^M: bad interpreter: No such file or directory
./nftp_vals.sh: ./detailedreport.sh: /bin/bash^M: bad interpreter: No such file or directory
./nftp_vals.sh: ./nftreader.sh: /bin/bash^M: bad interpreter: No such file or directory


Cause:
This issue is caused when creating scripts in Windows env and then porting over to run on a unix environment.

Unix uses different line feeds and carriage returns so can't read the file you created on Windows. Hence it is seeing ^M as an illegal character.

Resolution:
Just run dos2unix -k -o <filename> and the issue will be fixed.

E.g.:

[biadmin@illinxxxx scripts]$ dos2unix -k -o nftcontroller.sh
dos2unix: converting file nftcontroller.sh to UNIX format ...


[biadmin@illinxxxx scripts]$


By using the below command we can convert all the files within a directory and sub-directory in one shot!

find . -type f -exec dos2unix {} {} \;

Comments

Post a Comment

Popular posts from this blog

How to use a value between two different threads in Jmeter

Steps to Analyze AWR Report in Oracle

Correlation and checking in Results