The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Maintain full path of a script in a var when sourcing it from a different script mrbluegreen Shell Programming and Scripting 4 03-19-2008 06:31 PM
Bash Script to display directories in Path? debut Shell Programming and Scripting 1 11-09-2005 01:06 PM
Full path of executing script in ksh? BriceBu Shell Programming and Scripting 2 09-19-2005 06:29 AM
getting a shell script to know it's path Nat Shell Programming and Scripting 6 06-06-2004 05:08 PM
Determining absolute PATH within KSH script gsatch Shell Programming and Scripting 5 06-14-2002 09:23 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-2003
Registered User
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Set PATH using a script

I am a corporate user of Solaris ?? I have to write a lot of scripts to do little repetitive actions. To make this easier I would like to set the PATH so that I do not have to type ./ first before the script name.

Is there an easy script that will allow me to set this path when I log in???

My current path is;
$echo $PATH
/opt/jre1.2.2_05a/bin:/usr/dt/bin:/usr/openwin/bin:/bin:/usr/bin:/usr/ucb:/usr/openwin/bin:/opt/oracle/7.3.4/bin:/app/icop/aircrews/CIP/bin:/app/icop/aircrews/COP/bin:/usr/local/bin

I approached our sys admin people and they advised that this was set up to stop people writing scripts with the same name as existing scripts, lame yeah.
I would ideally like to edit the .bash_profile with ./~ but they will not allow that either.

HELP Please!!!

Forum Sponsor
  #2 (permalink)  
Old 02-27-2003
RTM's Avatar
RTM RTM is offline
Hog Hunter
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Quote:
From www.math.psu.edu:
When you type a command to be executed, Unix looks in a predefined list of directories to find an executable file of the same name as the command and executes it. This predefined list is called your path. An all-too-common practice by many Unix users is to put the working directory ``.'' in their path so they can execute any executable file in their working directory, wherever they happen to be in the system, just by typing its name.

This is not a big savings: if ``.'' is not in your path you merely have to type ./mycommand instead of mycommand. Moreover, having ``.'' in your path, especially near the beginning of it, puts you at risk. A vandal might create an executable file called ls in some directory. If you are in that directory and type ls, thinking it will list the directory, you will execute the cracker's command; if he were nasty enough, the command could destroy your files or create security holes that the person can later exploit.
If you REALLY need it, create a script that changes your PATH to include your complete home path (ie. /home/username/bin) instead of . - this will at the least keep you from running the wrong scripts. You would then have to run . /home/username/myscript4path to source it to your process.

#!/bin/ksh
export PATH=$PATH:/home/username/bin
exit

(Sorry, haven't messed with bash - should be close though)
  #3 (permalink)  
Old 02-27-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,207
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
Well, if you've been told not to change your PATH, then you perhaps should not do that. If I have a script in my home directory, I use ./script too. But I do it for security. And I have to say that typing ./ does not bother me. But you can avoid that without changing your PATH.

If you use the command:
alias script=/full/path/to/script
then from now on, you can just use "script" to run the command.

alias commands can be put in your .bash_profile file. I wasn't clear if you are allowed to edit that file at all. You could just put your alias commands in a file called "setup" or something. And then use this command:
. ./setup
to cause your shell to process that file. Note that leading dot. This is a little different than running a script. A dot command causes the current shell to read commands from the named file.

So give aliases a try. You get the result you wanted: no leading ./ required. And the sysadmins are happy since you are using the prescribed PATH.
Google UNIX.COM
Closed Thread



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 07:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102