# shell script location w/ Panther



## ropers (Feb 24, 2004)

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


----------



## scruffy (Feb 24, 2004)

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.


----------



## ropers (Feb 24, 2004)

Hmm, thanks for the swift reply, but that didn't seem to work.
So I did this to diagnose:


```
Last login: Tue Feb 24 20:19:31 on console
Welcome to Darwin!
[B]DigitalGoddess:~ ropers$[/B] pwd
/Users/ropers
[B]DigitalGoddess:~ ropers$[/B] 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
[B]DigitalGoddess:~ ropers$[/B] cr2lf
-bash: cr2lf: command not found
[B]DigitalGoddess:~ ropers$ [COLOR=DarkRed]echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin[/COLOR][/B]
[B]DigitalGoddess:~ ropers$[/B] cat .bashrc
# user-specific .bashrc file for interactive bash(1) shells
PATH=${PATH}:/Users/ropers/bin
export PATH
[B]DigitalGoddess:~ ropers$[/B] 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"
[B]DigitalGoddess:~ ropers$[/B]
```

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.


----------



## rhg (Feb 25, 2004)

To solve this, create an additional ~/.bash_profile and put a single line into it:
. ~/.bashrc

Hope this helps


----------



## rhg (Feb 25, 2004)

BTW: A reboot is absolutely not required in this context


----------



## ropers (Feb 25, 2004)

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


----------



## scruffy (Feb 25, 2004)

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.


----------



## ropers (Feb 26, 2004)

Excellent stuff! 
That sure licks it.
Thanks to both! 

rop


----------

