Help with the bash...alias/script...?

Joined
Oct 19, 2009
Messages
17
Reaction score
2
Points
3
Your Mac's Specs
MacBook Pro 13" 2.53GHz 4GB OSX 10.6
Hey everyone

I'm new to Mac OS, just switched from Ubuntu and sometimes its quite hard to get used to different stuff...

So, I searched the Internet for over an hour, but nothing could solve my problem. You will see it is quite simple (at least it was in ubuntu)

All I want to do is following:

To launch a particular program, I have to start X11 (xgterm), change directory and execute a command.

so basically its:

cd /iraf
xgterm -sb -geometry 80x24 -title "Image Reduction and Analysis Facility (IRAF)" -bg "black" -fg "orange" -bd "white" -cr "grey" -e "ecl"

and I don't want to type this every time I have to use the program. My question is: Can I create an alias, or write a script, so that I just have to type one simple command to execute those above in the bash?

Another thing is: In ubuntu I could launch all apps by typing their names (whatever was in /usr/local/bin). How do I create such a file, which enables me to launch a specific app from the terminal...? :(

I hope you can help me
cheers
 
Joined
May 2, 2009
Messages
480
Reaction score
13
Points
18
Your Mac's Specs
MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB
The concepts are the same on OSX so there should not be any real differences in what you are trying to do.

There is obviously no xgterm in OSX, it is simply xterm. Did you install X11 on your Mac? You didn't state the version of OSX you are using.In 10.6 (Snow Leopard) you would have the option to install this during installation. In 10.5 X11 will be on your install disks.

From what I am reading it sounds like you need to update your path to include the directories you want so you can simply type the name in the terminal. You can do this in either a .bash_login or .bashrc file. Example:

PATH=/usr/local/bin:'$'PATH:

export PATH

Note, there are no '' characters around the dollar sign, these were added for escaping.

My question is: Can I create an alias, or write a script, so that I just have to type one simple command to execute those above in the bash?

Scripting bash should work the same as on Linux so any scripts you write for those platforms should port easily to OSX. For the most part, bash is bash independent of platform on which you are running. Of course certain executables, variables etc may be different, but these can be easily resolved by pointing to the correct location.
 
Joined
Dec 13, 2007
Messages
256
Reaction score
10
Points
18
Location
United States of America
Your Mac's Specs
2.1GHz MacBook with 4GB RAM, Mac OS X 10.6, iLife and iWork ‘09
For your first question, all you'd need to do is add those commands to a script and then add it to a directory in your PATH to run them with a single command. [Edit: I forgot to mention that you'll probably have to chmod +x the script to run it directly.] In addition, if you want to run the script by opening it from the Finder or even from the Dock, write it as you would a .sh file and then save it as a .command file. If it isn't already, associate it with Terminal.app and then you can simply open it in the Finder or from the Dock to run the script. You can change whether the Terminal window stays open after it finished in the Shell tab of the Settings pane of Terminal's preferences.

As for your second question, just use the open command. For example, open -a Mail will open Mail.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top