ChrisW ChrisW - 1 month ago 5x
Perl Question

Ubuntu thinks bash script is perl

Saving the following code into a file, Ubuntu 14.04 correctly realises that it is bash:

#!/usr/bin/env bash

awk '{print $1 $2}' my_file

However trivially adding an instruction to awk about output formatting:

#!/usr/bin/env bash

awk 'BEGIN {ORS=" "} {print $1 $2}' my_file

Ubuntu now thinks this is Perl, as can be seen in the file properties and how gedit formats the code. What on earth is going on? (What I really care about is a much longer piece of bash code than this toy example.)

Saving it with extension
was what fooled Nautilus...


Did you try using a static shebang?


The env version of shebang is more flexible, but it can possibly baffle some programs (like gedit)...

However, it's not an O.S. problem: if you try this command:

$ file myscript
myscript: a /usr/bin/env bash script text executable

And also vim correctly colors syntax...

So the issue probably is just with gedit... :-(

UPDATE: As a result of the chat with OP, the issue is with the name of the script (script.bash).
Changing it to solves the issue.