sally

Discussion(s) about all things *Nix =-p

Moderators: boat, rickh

Post Reply
User avatar
boat
[NME] tried and true
[NME] tried and true
Posts: 2753
Joined: Fri Dec 07, 2001 8:00 pm
Location: Hampton Roads, VA
Contact:

sally

Post by boat » Thu Mar 08, 2007 12:47 pm

is there a way to make a shell script act sorta like a world wide binary?

for instance, i make a coupla little cheap/crude shell scripts for starting up different instances of a vnc session, that start them on different ports and/or window managers. they work, but i would have to start them from the home directory...so would there be a way to make it so it can used in the manner of typical commands, like ping or ls or whatever, where i can just type in the 'short name' instead of the full path?

<#/usr/local/> startvnc

vs

<#/usr/local/> ~/startvnc
(or <#/usr/local/> /usr/home/user/startvnc)

where any user could just do a "startvnc" from anywhere.

:?:

User avatar
Dictator
[NME] tried and true
[NME] tried and true
Posts: 989
Joined: Mon Jan 07, 2002 8:00 pm
Location: Central Pennsylvania

Post by Dictator » Fri Mar 09, 2007 8:55 am

What shell are you using?

With OpenBSD I set up a directory called bin in my home directory.

/home/dictator/bin
I can put any executable scripts in there.

In my .profile (which is openbsd's ksh), I have

Code: Select all

PATH=$PATH:/home/dictator/bin
export $PATH
Log out then log in. I can execute my scripts in bin directory from anywhere.

If you want to set up that for users, I think you can do that in /etc with shell's default profile.
Give me liberty, or I may well give you death.

User avatar
Grummun
[NME] tried and true
[NME] tried and true
Posts: 205
Joined: Wed Jan 12, 2005 3:49 pm
Location: Central OH
Contact:

Post by Grummun » Fri Mar 09, 2007 10:22 am

Like Dict is saying, but more generally:

It's a matter of executability and path. It sounds like you've already made your script executable (just a 'chmod +x <scriptname>').

After that, it just needs to be someplace that is in the average user's path (that is, the list of directories that the shell looks in for an executable when you enter a non-fully-qualified command at the prompt):

> echo $PATH
/bin:/usr/bin:/usr/local/bin:.

Find someplace that is in the standard path (/usr/local/bin is generally a good choice), and copy your script there. You should probably change the ownership to root or bin, and change the mode to 0755. Note that some shells build an internal hash of executables in the path when you login, and so won't immediately recognize a new executable. Logout and login is a simple fix for that.

User avatar
boat
[NME] tried and true
[NME] tried and true
Posts: 2753
Joined: Fri Dec 07, 2001 8:00 pm
Location: Hampton Roads, VA
Contact:

Post by boat » Fri Mar 09, 2007 12:42 pm

word, ill give those a try, thx. im using bash, but i flagged the scripts as sh scripts (#/bin/sh)

User avatar
[NME]T-Bone
[NME] tried and true
[NME] tried and true
Posts: 2818
Joined: Fri Jan 18, 2002 8:00 pm
Location: Sharpsville, PA

Post by [NME]T-Bone » Fri Mar 09, 2007 12:55 pm

I use /usr/local/bin for public scripts, otherwise I put them in a protected folder and add that folder to my path in my .profile or .login depending on my shell.
T-Bone

"If we hit that bullseye, the rest of the dominos
will fall like a house of cards. Checkmate."

User avatar
Grummun
[NME] tried and true
[NME] tried and true
Posts: 205
Joined: Wed Jan 12, 2005 3:49 pm
Location: Central OH
Contact:

Post by Grummun » Sat Mar 10, 2007 10:40 pm

boat wrote:word, ill give those a try, thx. im using bash, but i flagged the scripts as sh scripts (#/bin/sh)
/bin/sh may actually be a link to bash, although bash will behave differently if it's invoked as sh.

Anyway, the shell that the script is written in shouldn't matter; depending on your login shell, the method for setting the path might differ, but as long as your script is in your path, you should be hunky-dory. Hey-uck.

:P

User avatar
[NME]T-Bone
[NME] tried and true
[NME] tried and true
Posts: 2818
Joined: Fri Jan 18, 2002 8:00 pm
Location: Sharpsville, PA

Post by [NME]T-Bone » Tue Apr 10, 2007 1:45 pm

umm... just noticed sumfin. :oops:

shouldn't that be #!/bin/sh?
# by itself is just a comment.
T-Bone

"If we hit that bullseye, the rest of the dominos
will fall like a house of cards. Checkmate."

User avatar
boat
[NME] tried and true
[NME] tried and true
Posts: 2753
Joined: Fri Dec 07, 2001 8:00 pm
Location: Hampton Roads, VA
Contact:

Post by boat » Tue Apr 10, 2007 2:08 pm

you is correct sir...i just got lazy when typing it out :oops: :P ;)

Post Reply