PDA

View Full Version : question about a very simple shell script




abhishekit
Apr 13, 2004, 10:34 PM
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



bousozoku
Apr 13, 2004, 11:12 PM
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
Apr 14, 2004, 02:10 AM
yah it does..:D
thanks a lot bousozoku

abhishekit
Apr 14, 2004, 02:22 AM
another question though...how to deal with spaces in the file/application names?
thanks

gekko513
Apr 14, 2004, 06:23 AM
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

abhishekit
Apr 14, 2004, 11:31 AM
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

bousozoku
Apr 14, 2004, 12:46 PM
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.

abhishekit
Apr 14, 2004, 01:45 PM
oh yah...i missed it previously...thanks gecko..