0

I have myname.command script on OSX 10.8 from some app. It has Bash script, with signature (she-bang).

What other script formats can be inside *.command files? Maybe AppleScript or some others?

2

In the unix/linux world (afaik mac is running a unix variant) you wouldn't need any file extensions for programs, but it's good practice to give bash scripts the .sh, python scripts the .py, perl the .pl (etc.) extension for humans to identify those scripts without viewing the script checking the she-bang line. (I don't know if there are specific extensions for mac)

The important part is the executable flag chmod +x ./myscript.sh which marks the file as a program that can be executed.

The she-bang line is the first line in a file and starts with #! followed by the fullpath pointing to an executable /usr/bin/bash, /usr/bin/perl, /usr/bin/python.

On some Unix/Linux installations it could be possible that python, bashor any program is not located in /usr/bin/ but in /opt/python3.6 so the she-bang #! /usr/bin/python wouldn't start the program. So basically it's another good practice to start she-bang line with #!/usr/bin/env followed by the program you want to start ie. #!/usr/bin/env bash or #!/usr/bin/env python3.

This will look into the environment vars (PATH) for that given program.

  • Good text, but wanted to know: which scripts can be inside Mac's .command files. Seems only Bash. I mean filese with .command suffix. – RProgram Mar 28 '17 at 19:50
  • a .command file is just a file type that has been associated with the Terminal app, so when you double-click on it, the Finder launches Terminal, and passes it the file. .. So just try perl, awk or python whatever is installed on your system and look for a hello world example. – Michael D. Mar 28 '17 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.