I'm on Mountain Lion 10.8.5 and recently I've made a small shell script which just shows a message on the screen. To run it, I had run

chmod +x test-script.sh

and then using sh ./test-script.sh ran it successfully. So if I want to send this to friends, do they have to run chmod again? If so, how can I prevent it?

  • 2
    You should not have had to do the chmod if in fact you ran it by sh ./test-script.sh. The sh will read the file and run it regardless if the execute flag is set or not. You only need the execute flag if you run it directly, like ./test-script.sh – Kent Oct 9 '13 at 2:31
  • @Kent Can you say whether the file permissions will be preserved if the file is copied to a different machine? – Sri Harsha Chilakapati Oct 9 '13 at 4:40
  • Not really. It depends on many things. If it is sent as a single file via mail, then it will probably end up saved as the default for the recipient's mail program. If you copy it via a USB memory stick, then provided the USB memory supports the permissions, it should be ok. If you use scp over the network, the permissions will be preserved. If you are sending it to other Macs, you could put your file(s) into a disk image (dmg), in which case all the permissions would be preserved (even if the dmg was mailed) – Kent Oct 9 '13 at 7:00

You can instruct your friends to run it using sh ./test-script.sh. That would not require a chmod +x to be done.

If your friends also use OS X, another alternative is to package it as an app with Automator using the Run Shell Script action and share that with your friends. In this case the user can run it just like any other application on the system.

See Creating Shell Script Actions in the Automator Programming Guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .