Sponsored Content
Full Discussion: Problem with PATH
Top Forums Shell Programming and Scripting Problem with PATH Post 303020759 by jim mcnamara on Thursday 26th of July 2018 09:30:52 PM
Old 07-26-2018
I'm not sure what you think a PATH variable does. If a file has execute permissions (meaning you can run it by just typing the correct name of the file) then it can be run by typing the whole filename from anywhere

Code:
# example:
/path/to/shell.sh parameter1

This is awkward if you have your current directory somewhere else. So. PATH allows you to put directories into the variable. Then when you type the name no matter where your current directory is set, the PATH looks up the file, then lets you run it.

Example after adding the directory where shell.sh lives to PATH:
Code:
shell.sh parameter1

Not delete it
Not write to it.
Just execute it.

The which command helps you figure out what file you will execute before you try to run it. Why? Well, in the example: shell.sh could be in several places. So if you type shell.sh you could be running another script by accident. PATH can be a cause of this.

Code:
export PATH=".:${PATH}"

makes the current directory part of the PATH. Dangerous.

Example: I use t.shl as a throwaway temporary filename. So it could be in any of the my own directories.
Code:
which t.shl

tells me which one will run when I type the command.

Last edited by jim mcnamara; 07-26-2018 at 10:37 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PATH variable problem

root->echo $PATH /usr/ccs/bin:/opt/sfw/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin root->find / -name gcc /usr/local/bin/gcc /usr/local/doc/gcc root->which gcc no gcc in /usr/sbin /usr/bin Why cant it find gcc - the path looks okay doesnt it? I am running solaris 9 - and... (7 Replies)
Discussion started by: frustrated1
7 Replies

2. UNIX for Dummies Questions & Answers

cc path problem - no acceptable path found

Hello everyone, I'm a unix noob. I have a powerbook running mac os x 10.4 and for one of my classes I need to install the latest version of php (5.0.5). I'm following the instructions at http://developer.apple.com/internet/opensource/php.html to install but I've run into a problem. The... (2 Replies)
Discussion started by: kendokendokendo
2 Replies

3. Shell Programming and Scripting

path problem

hi , i have written csh script i am unable to set PATH variable in my script. my script is like this ===================================== # ! /bin/csh -f setenv PATH "$PATH:/opt/terascan/bin" ls -l > list lspass > pas peekauto > schedule \ num_days = 1 \ exit 0... (1 Reply)
Discussion started by: rajan_ka1
1 Replies

4. UNIX for Advanced & Expert Users

path problem

Hi i am writing a script containing processing commands which are reside in /opt/terascan/bin dir. if i run the script from command prompt it is working fine. but in crontab it is not working. if i give env command from command prompt it is showing /opt/terascan/bin dir in PATH variable. ... (10 Replies)
Discussion started by: rajan_ka1
10 Replies

5. Shell Programming and Scripting

Problem with File path

How to pass a file path to open a file? I am using cygwin. I want to open a file from a particular path, say C:\Test\File1,. This file path is stored in a variable. I am able to cat a file like this : cat "c:\Test\File1" but i want the same thing to happen in my script file through a variable... (3 Replies)
Discussion started by: sandeep_hi
3 Replies

6. Solaris

Problem Setting $PATH

I am trying to install the pkg-get package to a fresh install of Solaris 10. I am able to download and install correctly using the default directory for both pkg-get and wget as found on blastwave.org. When I issue the command "which wget and which pkg-get" it returns no wget or pkg-get found in... (1 Reply)
Discussion started by: greengrass
1 Replies

7. Infrastructure Monitoring

Problem with PATH

On one of the machines at work, we had Net-SNMP 5.2.3 installed, and I wanted to upgrade that to 5.4.2.1. So I downloaded the tar file, extracted it, did the configure, make, make test, make install, and everything worked. All the executable files (like snmpget, snmpset, snmpwalk) got copied to... (1 Reply)
Discussion started by: sllinux
1 Replies

8. Shell Programming and Scripting

if PATH contains a certain string problem!

Hi I am using MKS Toolkit c shell. I want to basically check if my PATH variable already contains a certain path directory so I tried this (it didnt work!): if: Expression Syntax if ( echo $path |grep -c c:/PROGRA~1/blah/blah ) then please help me get this little statement to work. ... (3 Replies)
Discussion started by: vas28r13
3 Replies

9. Shell Programming and Scripting

Problem with spaces in the path

Hi all, I have a variable test has the following value assigned.. could you please help on doing cd or ls to the value in the varible ... $echo $test /bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses $cd $test ksh: cd: bad argument count $cd... (3 Replies)
Discussion started by: firestar
3 Replies

10. UNIX for Beginners Questions & Answers

PATH problem

For the sake of not going insane and not buggering a load of needed system stuff, I have created a dir /mybin. (This is a Debian system.) I have then edited the /etc/profile and /etc/login.defs files and added :/mybin to all of the path variables. I have the file /mybin/mtp for... (2 Replies)
Discussion started by: MuntyScrunt
2 Replies
LOGIN(1)						   Linux Administrator's Manual 						  LOGIN(1)

NAME
login - Begin session on the system SYNOPSIS
login [ -p ] [ -h host ] [ -H ] [ -f username | username ] DESCRIPTION
login is used when signing onto a system. If no argument is given, login prompts for the username. The user is then prompted for a password, where approprate. Echoing is disabled to prevent revealing the password. Only a small number of password failures are permitted before login exits and the communications link is severed. If password aging has been enabled for the account, the user may be prompted for a new password before proceeding. He will be forced to provide his old password and the new password before continuing. Please refer to passwd(1) for more information. The user and group ID will be set according to their values in the file. There is one exception if the user ID is zero: in this case, only the primary group ID of the account is set. This should prevent that the system adminitrator cannot login in case of network problems. The value for $HOME, $SHELL, $PATH, $LOGNAME, and $MAIL are set according to the appropriate fields in the password entry. $PATH defaults to /usr/local/bin:/bin:/usr/bin:. for normal users, and to /sbin:/bin:/usr/sbin:/usr/bin for root if not other configured. The environment variable $TERM will be preserved, if it exists (other environment variables are preserved if the -p option is given) or be initialize to the terminal type on your tty line, as specified in /etc/ttytype. Then the user's shell is started. If no shell is specified for the user in /etc/passwd, then /bin/sh is used. If there is no directory specified in /etc/passwd, then / is used (the home directory is checked for the .hushlogin file described above). login reads the /etc/login.defs(5) configuration file. Please refer to this documenation for options which could be set. OPTIONS
-p Used by getty(8) to tell login not to destroy the environment -f Used to skip a second login authentication. This option is deprecated and should not be used. It does specifically not work for root. Using this option also means, that not all PAM functions are called. -h Used by other servers (i.e., telnetd(8)) to pass the name of the remote host to login so that it may be placed in utmp and wtmp. Only the superuser may use this option. -H Used by other servers (i.e., telnetd(8)) to tell login that printing the hostname should be suppressed in the login: prompt. FILES
/var/run/utmp - list of current login sessins /var/log/wtmp - list of previous login sessions /etc/passwd - user account information /etc/shadow - encrypted passwords and age information /etc/motd - system message file /etc/login.defs - configuration file SEE ALSO
init(8), getty(8), mail(1), passwd(1), passwd(5), environ(7), shutdown(8), login.defs(5) BUGS
A recursive login, as used to be possible in the good old days, no longer works; for most purposes su(1) is a satisfactory substitute. Indeed, for security reasons, login does a vhangup() system call to remove any possible listening processes on the tty. This is to avoid password sniffing. If one uses the command "login", then the surrounding shell gets killed by vhangup() because it's no longer the true owner of the tty. This can be avoided by using "exec login" in a top-level shell or xterm. AUTHOR
Derived from BSD login 5.40 (5/9/89) by Michael Glad (glad@daimi.dk) for HP-UX Ported to Linux 0.12: Peter Orbaek (poe@daimi.aau.dk) Added new features: Thorsten Kukuk (kukuk@suse.de) PAM Login 3.32 2. May 2007 LOGIN(1)
All times are GMT -4. The time now is 08:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy