question about a very simple shell script

Discussion in 'General Mac Discussion' started by abhishekit, Apr 13, 2004.

  1. abhishekit macrumors 65816

    abhishekit

    Joined:
    Nov 6, 2003
    Location:
    akron , ohio
    #1
    today i wrote a simple shell script to run apps from the terminal
    called it z.bash

    #!/bin/bash
    read -p "which app >>" name
    cd /
    cd applications
    open $name.app

    so that now when i write ./z.bash, i wd enter the name of app..and it wd run..and it works and its cool...
    now what wd be better, is that if it doesnt find the app under applications, it should look under applications/utilities..
    so what i want to ask is, can 'open' return an argument..
    like i want to simply put..

    if [open $name.app = FALSE] -----this is wrong-----
    cd utilities
    open $name.app
    fi

    so hopefully u get what i am asking..
    i wd really appreciate any help..
    thanks
     
  2. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #2
    This will work:

    #!/bin/bash
    read -p "Which app >> " name
    cd /Applications
    if open $name.app
    then
    # successful
    :
    else
    # not found
    cd ./Utilities
    open $name.app
    fi
     
  3. abhishekit thread starter macrumors 65816

    abhishekit

    Joined:
    Nov 6, 2003
    Location:
    akron , ohio
  4. abhishekit thread starter macrumors 65816

    abhishekit

    Joined:
    Nov 6, 2003
    Location:
    akron , ohio
    #4
    another question though...how to deal with spaces in the file/application names?
    thanks
     
  5. gekko513 macrumors 603

    gekko513

    Joined:
    Oct 16, 2003
    #5
    #!/bin/bash
    read -p "Which app >> " name
    cd /Applications
    if open "$name".app
    then
    # successful
    :
    else
    # not found
    cd ./Utilities
    open "$name".app
    fi
     
  6. abhishekit thread starter macrumors 65816

    abhishekit

    Joined:
    Nov 6, 2003
    Location:
    akron , ohio
    #6
    gekko:
    my question was..if the file or app has a space in its name, like 'directory access'..then you cant write ' open directory access' because it wont take the space in between..so thats the question..how to deal with spaces..
    thanks
     
  7. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #7
    That's how to handle it. I just tested the change with Disk Utility.
     
  8. abhishekit thread starter macrumors 65816

    abhishekit

    Joined:
    Nov 6, 2003
    Location:
    akron , ohio
    #8
    oh yah...i missed it previously...thanks gecko..
     

Share This Page