2

I have a shell file, and I need to make an executable that will work on any Mac without chmod +x, just by double clicking it. How can I do this? I've tried appify, but double clicking its result does not execute my file. I have also tried the solution presented in How to execute a shell script from within an app and show it in the terminal, but this results in the error Permission denied.

The script I'm trying to make executable is:

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $DIR

SLASH="/"

INFILE=`find $DIR -name "*.csv"`

DONE=`perl myfile.pl -i $INFILE -o output.csv -l $DIR$SLASH`

echo "File(s) are ready to use"

echo "Press [enter] to escape"

read terminate
Community
  • 1
  • 1
Aditya J.
  • 131
  • 2
  • 11
  • 2
    `bash yourfile.sh` – Ipor Sircer Nov 22 '16 at 14:57
  • An automator script/application would probably help here. – Anya Shenanigans Nov 22 '16 at 15:36
  • 1
    You can't magically make a file executable on another person's system. You have 3 things you need to make this work: 1. the shell script, 2. the perl script (in the same folder as the shell script) and 3. the input .csv file(s)? which are also in the same folder (this is starting to get really messy as the find would find output.csv as part of the list of input files). You need at a minimum an executable shell script to get the ball rolling, but as written, it's not going to work out well. – Anya Shenanigans Nov 22 '16 at 15:53
  • My deliverable is a folder with all the requirements to run the shell script. The end user would, in the best case scenario, just need to double click the executable and have the output file ready. – Aditya J. Nov 22 '16 at 15:59
  • It would probably be simpler to deliver a single Perl script that incorporates everything the shell script currently does. – chepner Nov 22 '16 at 16:04
  • 1
    If you're delivering a folder; it will have to be bundled. All typical forms of bundling (.zip, .tar) will respect the executable bit set on the files within the bundle, so this is one hurdle overcome. chepner's single perl script is probably a better solution; and could be embedded in an automator executable that can be signed (to get around gatekeeper) – Anya Shenanigans Nov 22 '16 at 16:09

1 Answers1

7

To make your file executable you need to add, surprisingly, the executable permission.

To do so you can run chmod +x filename.sh

This will make it so you can ./filename.sh and execute the file.

You'll see when you do a ls -lah that there will be an x added to the permissions on the left.

You can go further into user/group/world execution permissions, but that's another topic.

darryn.ten
  • 6,784
  • 3
  • 47
  • 65
  • 1
    note: "I need to make an executable that will work on any Mac without chmod +x, just by double clicking it". I am well aware that chmod +x will make my file executable on my computer, but I want to make an executable I can deliver to people who are opposed to terminal for whatever reason – Aditya J. Nov 22 '16 at 15:13
  • well then a (dangerous) `chmod 777 filename.sh` should sort that out for you, although I advise against it - check out the differences between user/group/world permissions – darryn.ten Nov 22 '16 at 15:14
  • This still results in a `"The file “filename.sh” could not be executed because you do not have appropriate access privileges."` on any other system – Aditya J. Nov 22 '16 at 15:25
  • `chmod 777` is never needed, `chmod +rx` should do to make sure that the file is executable by everyone. But the bigger question is why `filename.sh` lost its executable permission bits "in transit" - assuming it had them to begin with. – mklement0 Nov 22 '16 at 21:10