Weird shell script problem + solution


Yesterday, I installed a fresh Java EE application server to run a test on an application I was working on. The installation of the application server was as simple as unzipping a distribution archive. As with most application servers, the server could be started by running a shell script from the command line. This was all familiar to me, as I already had another instance of the same server installed on my MacBook. However, when I tried to run the script, I got surprised by an error message:

-bash: ./run.sh: /bin/sh: bad interpreter: Operation not permitted
Code language: JavaScript (javascript)

First thing I did was checking the permissions for the file:

ls -al -rwxr-xr-x@ 1 bkummel staff 8107 22 mei 2009 run.sh

At first sight, there was nothing wrong. The file did have execute permissions. But when I compared the file with the one of the other server-instance, I noticed there was an extra @-sign right after the permissions. With the help from Google and two helpful colleagues, I found some information on the internet. It turns out the @-sign indicates that the file has extended attributes. Luckily, one of the articles also points to the `xattr` command, that can be used to read and manipulate the extended attributes. So, I continued by querying what extended attributes my file had:

xattr -l run.sh com.apple.quarantine: 0006;4f8d509d;Google\x20Chrome.app;D9C08949-17F6-44CE-8937-36DB935B50A1|com.google.Chrome

Now I got a clue! This is probably the mechanism that normally causes those “Xyz is an application downloaded from the internet. Are you sure you want to open it?”-dialogs to appear. And apparently on the command line the effect is the error message printed before. So instead of just clicking the “open” button in the dialog, I had to find a way to remove this extended attribute. Luckily, that’s not too complicated:

xattr -d com.apple.quarantine run.sh
Code language: CSS (css)

Now the attribute is deleted and the script runs without problems. So in case you ever encounter a mysteriously not running script, don’t forget to check for extended attributes!


Leave a Reply

%d bloggers like this: