How to execute install.sh under Big Sur

command lineterminal

I am quite a n00b on MacOS and it feels like it got worse with Big Sur.

I need to execute a .sh script to complete the setup of a 3d party app. The instructions say to "execute install.sh"
The first obstacle I found was that the file did't have the -x attribute set, so "sudo chmod +x ./install.sh" did that. Yet, when I do "sudo ./install.sh" it barfs "sudo: unable to execute ./install.sh: No such file or directory"

The file exists:

ls -l install.sh  
-rwxr-xr-x@ 1 mbaas  staff  740 14 Feb 12:44 install.sh

What am I missing?

Additional details:

  • first line of script has the usual shebang:

    #!/bin/sh

  • according to these instructions, the following shows the association of sh-files:

readlink /var/select/sh
/bin/bash
  • does that shell exist?
ls -l /bin/bash
-r-xr-xr-x  1 root  wheel  1296640  1 Jan  2020 /bin/bash
ls -l /bin/sh
rwxr-xr-x  1 root  wheel  120912  1 Jan  2020 /bin/sh

That's interesting:

ls -lOe@ install.sh
ls: install.sh : No such file or directory

I thought I may have been in the wrong directory, so just to verify:

ls -l install.sh
-rwxr-xr-x@ 1 mbaas  staff  757 14 Feb 18:08 install.sh
  • and finally: hexdump -Cv -n 32 install.sh
00000000  23 21 2f 62 69 6e 2f 73  68 0d 0a 73 65 74 20 2d  |#!/bin/sh..set -|
00000010  65 0d 0a 0d 0a 42 41 53  45 44 49 52 3d 24 28 64  |e....BASEDIR=$(d|
00000020

Best Answer

.sh files are what is known as "shell scripts". Basically, when you run a .sh file, you're not executing that file directly - instead the contents of the file is given to a specific program as instructions to follow. That specific program is named in the first line of the .sh file prefixed by #!.

The error message you see means that the program specified by that first line of the file does not exist (at the given location). Essentially the shell script is incorrectly made.

If you have knowledge about the purpose of the script, and how your system is setup, you might be able to use a texteditor to change the file line of the file to point to the correct program - otherwise I would contact the supplier of the program and ask for updated files and instructions.

UPDATE: You have updated your question with the first part of the contents of the shell script. This makes it clear that the problem is that the first line of the script ends not with a normal newline symbol (LF), but rather a Windows-style newline consisting of two symbols (CR LF).

You can fix the line feeds in the file by running this command in the same folder as the shell script using the Terminal:

perl -pi -e 's/\r\n|\n|\r/\n/g' install.sh
Related Question