Results 1 to 11 of 11
  1. #1
    Making a Shell Script Executable
    surfwax95's Avatar
    Member Since
    Aug 27, 2005
    Location
    Fayetteville, AR
    Posts
    2,406
    Specs:
    15" Powerbook G4 24" iMac iPhone 3Gs
    Making a Shell Script Executable
    I made a simple script with pico, but I don't know how to make it executable from the Finder. I've tried changing the suffix to .command, but it just says "Terminal can't open this file, it's not executable".

    I've looked a little at "chmod" but really don't understand how it works fully. So if anyone could help me out, please do.
    Thanks.
    I try to Command+Shift+/ when I can.
    They're - Their - There | Two - Too - To | You're - Your | MAC - Mac
    I was on the M-F honor roll for October, 2006.

  2. #2
    Making a Shell Script Executable
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    Try chmod 755 script name
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  3. #3
    Making a Shell Script Executable
    surfwax95's Avatar
    Member Since
    Aug 27, 2005
    Location
    Fayetteville, AR
    Posts
    2,406
    Specs:
    15" Powerbook G4 24" iMac iPhone 3Gs
    Beeeautiful. That worked perfectly. :mac:

    Now, could you explain WHY that worked perfectly? What does the 755 mean?

    I "man"ed chmod, but didn't see the 755 code.
    I try to Command+Shift+/ when I can.
    They're - Their - There | Two - Too - To | You're - Your | MAC - Mac
    I was on the M-F honor roll for October, 2006.

  4. #4
    Making a Shell Script Executable
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    If you look at the chomd man pages, you see that you can change the permissions two ways. I find using the numbers to be easier.

    Here is what it breaks down too.

    read = 4; write = 2; execute = 1

    There are three permission fields to each file; owner, group and other (world).
    In that order. So if you get a directory listing (long) of a file you might see the following:

    -rwxr-xr-x 5 rman user 200 13 Dec 2005 script

    Looking at the string -rwxr-xr-x. you will see the first -, which is either l (link) or d (directory) and t (I think stick bit - no sure there). The remaining string you can break up in to three octets rwx (owner), r-x (group), and r-x (other).

    If you look at the above numbers the string would equate to this 755. The ower have read, write and execute persmissions. Whereas the group and other only has read and execute permissions.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

  5. #5
    Making a Shell Script Executable

    Member Since
    Dec 30, 2007
    Posts
    1
    You can also use chmod u+x script-name or just chmod x script-name, that will change the permissions to excitable (assuming your the owner of the file) if you want you can also view the file permissions using ls -l in case anyone was wondering about that as well.

  6. #6
    Making a Shell Script Executable

    Member Since
    Aug 26, 2009
    Posts
    3
    how do I use chmod 755. I have a file that I want to make executable with chmod 755. I am new at this. Thanks.

  7. #7
    Making a Shell Script Executable
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    You have to execute that in the Terminal (/Applications/Utilities/Terminal.app). So, if I wanted to make ~/test.sh executable, I could execute the following:
    Code:
    chmod 755 ~/test.sh
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  8. #8
    Making a Shell Script Executable

    Member Since
    Aug 26, 2009
    Posts
    3
    thanks. I'll try that.

  9. #9
    Making a Shell Script Executable

    Member Since
    Aug 26, 2009
    Posts
    3
    Does the location of the file matter? I have it in OSX/Users/brittburns/ . Would I type "chmod 755 OSX/Users/brittburns/(file name)" ?

  10. #10
    Making a Shell Script Executable
    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,395
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    There should be no OSX at the front of that directory. / is the top level directory, much like C: on a Windows machine.

    The only restriction is that you need permissions for that file. If it's in your user directory, you should be fine.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  11. #11
    Making a Shell Script Executable

    Member Since
    Aug 25, 2010
    Posts
    1
    A couple options
    EDIT: I posted this in the wrong place, and cannot seem to remove it. But it's semi-relevant, so here it is.

    One way to make a script an "Unix executable file" (with an icon that is the dark colored rectangular with '.exec' written on it) is to use 'cat' to get rid of the Apple file-type encoding. If you have a script called 'script.sh', and you rename it to 'script' with no extension, the file will continue to be identified as a '.sh' file, and thus will want to be opened with a text editor, unless of course you change the settings. But you can change the default application to Terminal by erasing the file-type info (with 'cat') and turning it into an executable file (with 'chmod'). The following script uses this method to change a file to an executable:
    Code:
    #!/bin/bash
    # makeexec.sh
    #
    # changes the file type to "Unix executable file"
    # by cat and chmod +x
    
    if [ -z "$1" ]; then 
      echo usage: $0 directory
      exit
    fi
    
    for var in "$@"
    do
    if [ -f $var ]; then
    	newname=${var%.*};
    	cat $var > $newname
    	chmod +x $newname
    fi
    done
    
    exit
    The only problem with this method is that everytime you edit the executable, it wants to turn back into a .txt file. So, for this reason, I made this makeexec.sh script and put it in /usr/bin to speed up the process. I just do my edits, and then finish with a
    Code:
    makeexec.sh file.sh
    once I am done, which makes an executable file called file.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help making shell script for basic command
    By ericconn in forum OS X - Operating System
    Replies: 3
    Last Post: 09-26-2012, 04:08 PM
  2. Shell script help
    By Hyper in forum OS X - Development and Darwin
    Replies: 12
    Last Post: 05-22-2011, 11:36 AM
  3. Terminal -- shell script -- script will only read two lines of a file
    By Straitsfan in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-30-2011, 09:04 PM
  4. Terminal.app/bash: Creating An Executable Shell Script
    By ebay in forum Running Windows (or anything else) on your Mac
    Replies: 7
    Last Post: 04-28-2008, 06:43 PM
  5. Shell Script on Desktop
    By starrin in forum OS X - Operating System
    Replies: 2
    Last Post: 07-28-2004, 11:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •