Re: Strange error running scripts. without #!/usr/bin/bash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On May 21, 2023, at 09:47, Jonathan Billings <billings@xxxxxxxxxx> wrote:


On May 20, 2023, at 22:18, Michael D. Setzer II <msetzerii@xxxxxxxxx> wrote:


Recently was getting a strange error when running a script that didn't have #!/usr/bin/bash at top?
free(): invalid next size (fast)
Aborted (core dumped)
Just adding the line fixes the issue, but not sure why??
Have run the script before with no such error, but had been a while?  Script was just one line? Now 2 lines.
#!/usr/bin/bash
boincmgr -e /home/msetzerii/BOINC -d /home/msetzerii/BOINC

So, the #! as the first two bytes of the shell script tells the OS that it is a shell script and to invoke what follows with the file as a parameter. So in your example, it will invoke /usr/bin/bash /path/to/script.sh. 

Without the shebang (what we call ‘#!’), the OS looks at the ‘bo’ to identify what kind of executable it is. That’s the first two bytes of the file, because it starts with the text ‘boincmgr’.

By default, if the OS doesn’t recognize the file’s “magic number” (those two first bytes), it executes it with /bin/sh by default.  However, on your system it thinks your executable is some sort of binary program and instead of interpreting it as a shell script, it tries to execute as a loaded executable. And of course, that crashes. Or maybe your /bin/sh is broken somehow as to generate that error. 

Basically, without the shebang, shell scripts will have unpredictable results. Don’t do it.


This is what I’d expect would happen:

$ echo boincmgr >/tmp/test.sh
$ chmod +x /tmp/test.sh
$ file /tmp/test.sh
/tmp/test.sh: ASCII text
$ /tmp/test.sh
/tmp/test.sh: line 1: boincmgr: command not found
$

So I suspect something weird is going on that isn’t being mentioned. What happens if you run /bin/sh /path/to/script.sh (replacing my example path with the path to your script)?

--
Jonathan Billings
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux