# Linux and Perl, bad interpreter error

**URL:** <https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513>\
**Category:** Factual Questions\
**Created:** [January 26, 2010, 2:51pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513 "2010-01-26T14:51:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [January 26, 2010, 2:51pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/1 "2010-01-26T14:51:29Z")

</div>

I had a perl script that scans an ugly ugly HL7 interface error log that was originally made for AIX 5.3. That server is gone and i copied the script to the new Red Hat server. This is what happened when i tried to run it:

```auto

[root@StupidRedHat /]# errorscan
: bad interpreter: No such file or directoryrl

```

So i used vi to change the # line from **#!/usr/bin/perl** to **#!/usr/local/bin/perl** (which perl). But i still get the exact same error message. However, if i run perl using errorscan as an argument it works:

```auto

[root@StupidRedHat /]# cd /usr/bin
[root@StupidRedHat bin]# perl errorscan

Enter the path of the log file to be searched:

```

What else does Linux need to make this work the right way?

---

<div class="post-metadata">

**Author:** ![Simplicio](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Simplicio](https://boards.straightdope.com/u/Simplicio)\
**Post date:** [January 26, 2010, 3:01pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/2 "2010-01-26T15:01:54Z")

</div>

Type “which perl” into the command line. That will give you the address of the perl interperter executable that is being invoked when you type “perl errorscan”

ETA: and looking at your post again, you already did this. Nvm

---

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [January 26, 2010, 3:04pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/3 "2010-01-26T15:04:02Z")

</div>

I did, that is how i knew to change the bang line

> [@SlickRoenick](#):
>
> from **#!/usr/bin/perl** to **#!/usr/local/bin/perl** (which perl)

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 26, 2010, 3:05pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/4 "2010-01-26T15:05:59Z")

</div>

There might be some characters in the “errorscan” script that’s throwing things off, since you did copy it from a non-linux system. Do a vi -b errorscan and look for things you didn’t realize you were there, or in vi use the :%!xxd command to see it in hex.

---

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [January 26, 2010, 3:11pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/5 "2010-01-26T15:11:50Z")

</div>

> [@arseNal](#):
>
> There might be some characters in the “errorscan” script that’s throwing things off, since you did copy it from a non-linux system. Do a vi -b errorscan and look for things you didn’t realize you were there, or in vi use the :%!xxd command to see it in hex.

I used the -b switch and every end of line had a ^M at the end of it. What is that from? I used ftp and set it to binary mode, should it have been ASCII?

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 26, 2010, 3:48pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/6 "2010-01-26T15:48:30Z")

</div>

> [@SlickRoenick](#):
>
> I used the -b switch and every end of line had a ^M at the end of it. What is that from? I used ftp and set it to binary mode, should it have been ASCII?

Yeah. Just convert it using dos2unix.

```auto

dos2unix errorscan > errorscan_new

./errorscan_new

```

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [January 26, 2010, 3:56pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/7 "2010-01-26T15:56:47Z")

</div>

> [@SlickRoenick](#):
>
> I used the -b switch and every end of line had a ^M at the end of it. What is that from? I used ftp and set it to binary mode, should it have been ASCII?

Yes, you should always use text-mode when transferring scripts for this reason. The ^M characters are carriage-returns (\r). DOS and Windows-based OSes use CRLF (  
) for their end-of-lines. Unix-type OSes use LF (  
) alone.

The Linux kernel does not take kindly to carriage returns appearing on the #! line, and will interpret them as being part of the filename of the interpreter, which file obviously doesn’t exist. Perl itself is more lenient.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [January 27, 2010, 8:10am UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/8 "2010-01-27T08:10:02Z")

</div>

There’s just one thing I don’t understand: Where did the linefeeds come from? I’m pretty sure AIX doesn’t use them any more than Linux does, and FTP won’t add them in binary mode.

---

<div class="post-metadata">

**Author:** ![MrDibble](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mrdibble/32/114_2.png) [@MrDibble](https://boards.straightdope.com/u/MrDibble)\
**Post date:** [January 27, 2010, 8:32am UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/9 "2010-01-27T08:32:43Z")

</div>

maybe he used a Windows machine as intermediary?

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 27, 2010, 1:15pm UTC](https://boards.straightdope.com/t/linux-and-perl-bad-interpreter-error/526513/10 "2010-01-27T13:15:44Z")

</div>

Maybe they were there on the AIX box too, except AIX was able to handle them.

I haven’t used AIX in forever tho, so who knows.
