image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Closed Thread
 
Thread Tools
  #1  
Old February 24th, 2004, 10:36 AM
Registered User
 
Join Date: Dec 2001
Location: Dublin
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ropers is on a distinguished road
shell script location w/ Panther

I'm sure these things have only been asked a thousand times (I just couldn't find the answers):

I am running Panther (Mac OS X ver. 10.3.2.[at present]).
I am using the (default) bash shell.
I am *starting* to write shell scripts.

I would like to "install" some shell scripts, so that they are always available for execution (for me only), and preferably so that they can be called by simply typing their filename (plus optional parameters).
I don't want to type ./filename or something.

I *suspect* I'd need to do the following:
- Write the script(s) and store it/them in a location where it's good practice to put them.
- Write/edit a ~/.bashrc file and add an alias (for every command I want included).

Am I right with the above?
Would there be additional things I'd need to do?
Also, what location would be good practice to put these things in?

Alternatively, there wouldn't be a way to just include the files in the path and it would work, would it? (I remember this from goody ole DOS.)

Also, I'd be interested to learn how I can make these scripts available to everyone (but otherwise as above). This would obviously mean storing them in a commonly accessible location -- again, I'd like to know where it's good practice to put them. Plus, I'd need something else than ~/.bashrc.

Again, if I'm entirely on the wrong track, please do not hesitate correcting me. I am not looking for a quick fix, I am looking for a solution that's truly best practice with my OS.

Many thanks in advance!!!



rop
__________________
http://www.ropersonline.com
  #2  
Old February 24th, 2004, 01:50 PM
scruffy's Avatar
Notorious Olive Counter
 
Join Date: Dec 2000
Location: Soviet Canuckistan
Posts: 1,726
Thanks: 0
Thanked 0 Times in 0 Posts
scruffy is on a distinguished road
it's a little easier than that - no need to explicitly include every single script if you put them all the same place. Typically you'd put them in a subfolder of your home directory. Then you'd add that folder to your shell's PATH variable - that's the list of places the shell looks for programs to run when you don't specify a path explicitly.

If you put all your scripts in the folder /Users/ropers/bin (which is a fairly conventional place for it), then you could add these lines to your .bashrc:

PATH=${PATH}:/Users/ropers/bin
export PATH

You'd want to make sure that the /Users/ropers/bin is not writable by anyone but you, and the same goes for the scripts themselves, but other than that there's nothing special to it.

to make them available for everyone, a conventional place to put them would be /usr/local/bin. If your path doesn't include /usr/local/bin, you'd have to add that in your .bashrc. To do it once for everyone, you could make the change in /etc/bashrc, which is checked by everyone's shell. Again, make sure the scripts are not writable by anyone but you.
__________________

What is the robbing of a bank compared to the founding of a bank?
-- Bertold Brecht
  #3  
Old February 24th, 2004, 02:40 PM
Registered User
 
Join Date: Dec 2001
Location: Dublin
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ropers is on a distinguished road
Hmm, thanks for the swift reply, but that didn't seem to work.
So I did this to diagnose:

Code:
Last login: Tue Feb 24 20:19:31 on console
Welcome to Darwin!
DigitalGoddess:~ ropers$ pwd
/Users/ropers
DigitalGoddess:~ ropers$ ll bin
total 16
drwxr-xr-x   4 ropers  ropers  136 24 Feb 19:58 .
drwxr-xr-x  29 ropers  ropers  986 24 Feb 20:01 ..
-rwxr-xr-x   1 ropers  ropers  176 23 Feb 22:59 cr2lf
-rw-r--r--   1 ropers  ropers  127 23 Feb 22:50 test
DigitalGoddess:~ ropers$ cr2lf
-bash: cr2lf: command not found
DigitalGoddess:~ ropers$ echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin DigitalGoddess:~ ropers$ cat .bashrc
# user-specific .bashrc file for interactive bash(1) shells
PATH=${PATH}:/Users/ropers/bin
export PATH
DigitalGoddess:~ ropers$ cat /etc/bashrc 
# System-wide .bashrc file for interactive bash(1) shells.
PS1='\h:\w \u\$ '
# Make bash check it's window size after a process completes
shopt -s checkwinsize
# set up ll to work globally
alias ll="ls -al"
DigitalGoddess:~ ropers$
looks that somehow that .bashrc isn't being executed?
Any ideas?

Many thanks, rop

PS: I did fully reboot after applying the changes, just in case.
__________________
http://www.ropersonline.com
  #4  
Old February 25th, 2004, 07:13 AM
rhg rhg is offline
Registered User
 
Join Date: Dec 2002
Location: Velbert, Germany
Posts: 220
Thanks: 0
Thanked 0 Times in 0 Posts
rhg is on a distinguished road
To solve this, create an additional ~/.bash_profile and put a single line into it:
. ~/.bashrc

Hope this helps
  #5  
Old February 25th, 2004, 07:14 AM
rhg rhg is offline
Registered User
 
Join Date: Dec 2002
Location: Velbert, Germany
Posts: 220
Thanks: 0
Thanked 0 Times in 0 Posts
rhg is on a distinguished road
BTW: A reboot is absolutely not required in this context
  #6  
Old February 25th, 2004, 10:20 AM
Registered User
 
Join Date: Dec 2001
Location: Dublin
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ropers is on a distinguished road
Excellent. That worked like a charm
Thanks a bunch to both!!


---
Now to add another question:
I ran across this article, in which (further down, in the post titled Wilfredo Sanchez Jr.) a contributor makes reference to some design decision where Apple appears to use a complex approach (referred to in connection with a "Project Athena").

Now my question is this: In applying the solution given above in THIS thread, am I bypassing some conventions, ie. should I rather be doing things another way?

I know it's kinda confusing, but that's because I'm kinda confused about "what's right" and whether what we're doing here is the "best practice" way of things. "Greenhorn" concerns perhaps, but there you go, nobody's safe from them. ;-)

rop
__________________
http://www.ropersonline.com
  #7  
Old February 25th, 2004, 08:31 PM
scruffy's Avatar
Notorious Olive Counter
 
Join Date: Dec 2000
Location: Soviet Canuckistan
Posts: 1,726
Thanks: 0
Thanked 0 Times in 0 Posts
scruffy is on a distinguished road
From 10.0 to 10.2.whatever, the default shell was tcsh, and there was a whole range of init scripts all over the place that were used. It made for a really nice rich environment without much customization, but if one of your customizations didn't work like you expected, and you were trying to debug, it made it hella difficult to track down what order scripts were run in and so on. That's what that article applies to.

As of 10.3, the default shell is bash, and so that whole scheme no longer applies. Even if you go back to using tcsh, all the /usr/share/init/tcsh and ~/Library/init/tcsh stuff is no longer there.
__________________

What is the robbing of a bank compared to the founding of a bank?
-- Bertold Brecht
  #8  
Old February 26th, 2004, 01:32 PM
Registered User
 
Join Date: Dec 2001
Location: Dublin
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
ropers is on a distinguished road
Excellent stuff!
That sure licks it.
Thanks to both!

rop
__________________
http://www.ropersonline.com
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 08:46 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.