Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

abhishekit

macrumors 65816
Original poster
Nov 6, 2003
1,297
0
akron , ohio
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
 
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
 
abhishekit said:
another question though...how to deal with spaces in the file/application names?
thanks
#!/bin/bash
read -p "Which app >> " name
cd /Applications
if open "$name".app
then
# successful
:
else
# not found
cd ./Utilities
open "$name".app
fi
 
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
 
abhishekit said:
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

That's how to handle it. I just tested the change with Disk Utility.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.