[SW-TECH] shebang perl not work in Unix

AREA: Scripting/Perl

PROBLEM:

  • This problem bothered me for a while so I wanna share what I found out:
  • My perl script starts with the standard shebang:
    #!/usr/bin/perl
  • But does not pass it to perl, instead it complains:
    "bad interpreter: No such file or directory"

ROOT CAUSE:

  • I initially edited my file on Windows using Notepad++ . DOS/Windows has a different newline format and puts extra unwanted control characters in the file.

SOLUTION:

  • If found the solution on the web in this link :
  • The solution is to cleanup my script removing unnecessary CR/LF (Carriage Return/Line feed character) that Unix/Linux shell does not like.
  • I created the script below based on the newsgroup I mentioned and added exec permission:
  • dos2linux.sh
    #!/bin/bash
    echo "$0: Cleanup text files edited in DOS/Windows for Unix format by removing CR/LF"
    perl -pi -e 's/\r\n$/\n/' $*
  • I cleaned up my script by running as follows:
    dos2linux.sh scriptname.sh
  • After this my perl script works fine.

Comments

Popular posts from this blog

Get Rid of Anger - wikiHow

To GBS/CIDP/Polyneuropathy Patients and Friends

Fav-Song Lyrics-004: Are you Lonesome Tonight - by Elvis Presley