Linux Apps Tutorials - Herong's Tutorial Examples - v1.03, by Herong Yang
"Operation not permitted" Error on macOS
This section provides a tutorial example showing 'Operation not permitted' error when executing a shell script file on macOS system.
On macOS systems, you may get the "Operation not permitted" when accessing a file with a command in the "Terminal" window. Here is my experience on my Mac computer.
1. Download a package in ZIP file format.
2. Unzip the package, I see a shell script file, start.sh.
3. Run the script file, I see the error, "Operation not permitted".
herong$ ls -l *.sh -rwxr-xr-x@ 1 herong staff 3922 start.sh herong$ ./start.sh -bash: ./start.sh: Operation not permitted
4. Copy the script file and replace the content with one line. I still get the same error.
herong$ cp -p start.sh s.sh herong$ echo 'echo "Hello world!"' > s.sh herong$ ./s.sh -bash: ./s.sh: Operation not permitted
5. Create a new script file. I can run it no problem.
herong$ echo 'echo "Hello world!"' > n.sh herong$ chmod +x n.sh herong$ ./n.sh Hello world!
6. Compare both script files with "ls" and "diff" commands. I see no differences.
herong$ diff s.sh n.sh herong$ ls -l *.sh -rwxr-xr-x@ 1 herong staff 20 n.sh -rwxr-xr-x@ 1 herong staff 20 s.sh -rwxr-xr-x@ 1 herong staff 3922 start.sh
The easier solution is to clone "start.sh" by taking its content only.
herong$ cat start.sh > start-2.sh herong$ chmod +x start-2.sh herong$ ./start-2.sh ...
So there must be a hidden attribute on "start.sh" that prevents the shell command to execute it.
On the Internet, I see articles relating the "Operation not permitted" error to 2 possible root causes. But I don't think they apply to my issue presented above.
Table of Contents
"more", "head" and "cat" - Read Files
"split" and "cat" - Split and Join Files
"compress/uncompress" - Compressed *.Z Files
"gzip/gunzip" - Compressed *.gz Files
"xz/unxz" - Compressed *.xz or *.lzma Files
"tar -c" and "tar -x" - Create and Extract Archive Files
"zip" and "unzip" - Create and Extract ZIP Files
►"Operation not permitted" Error on macOS
Running Apache HTTP Server (httpd) on Linux Systems
Running Apache Tomcat on Linux Systems
Running PHP Scripts on Linux Systems
Running MySQL Database Server on Linux Systems
Running Python Scripts on Linux Systems
Conda - Environment and Package Manager