LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-19-2009, 06:59 PM   #1
gmartin
Member
 
Registered: Mar 2003
Location: PA
Distribution: Slackware 13.37 Linux Reg # 341245
Posts: 285

Rep: Reputation: 40
Why does this work?


i was just fooled by something and I need your help to understand. I have a script that runs AlienBob's script to build an install iso. My script is in /usr/local/bin. I wasn't sure of its location so I 'cd' to the directory, ran 'ls' then ran the script. Problem is that I didn't precede the script with ./ but it ran any way. My experience tells me it shouldn't have worked.

Only thing i can guess is the /usr/local/bin is in my path. Does that change the requirement for the './'
 
Old 07-19-2009, 07:08 PM   #2
chigurh8
Member
 
Registered: Jul 2009
Distribution: Ubuntu, Gentoo
Posts: 102

Rep: Reputation: 18
Yeah, if it's in your path, ./ isn't needed.
 
Old 07-19-2009, 07:11 PM   #3
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL, USA
Distribution: Arch, Gentoo
Posts: 6,940

Rep: Reputation: 129Reputation: 129
You're in a bash shell - and it's in your $PATH, correct.
Code:
root@paul:/usr/local/sbin# mirror-slackware64-current.sh
#
# Mirroring slackware64-current from rsync.osuosl.org::slackware/slackware64-current ...
#
Changing to /backup2/ftp/pub/Linux/Slackware/slackware64-current ...
Mon Jul 20 08:08:02 CST 2009 [6553]: Getting ChangeLog.txt...
/backup2/ftp/pub/Linux/Slackware/slackware64-current
Mon Jul 20 08:08:06 CST 2009 [6553]: No difference found, exiting now....
Edit: Sorry, chigurh8, we got a lag in China ... like 50 centuries.

Last edited by Bruce Hill; 07-19-2009 at 07:13 PM.
 
Old 07-19-2009, 07:12 PM   #4
Nille_kungen
Member
 
Registered: Jul 2005
Distribution: Slackware64-current
Posts: 587

Rep: Reputation: 201Reputation: 201Reputation: 201
It work because it's in your $PATH and has the executable bit set.
'which foo.sh' should output the script if it's in your path.
The ./ only executes the script in 'pwd' and doesn't execute the script you got in your $PATH.
EDIT: i see i was to slow as well but i'm a slow typer

Last edited by Nille_kungen; 07-19-2009 at 07:14 PM.
 
Old 07-19-2009, 07:43 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Have a look at the bash startup file /etc/profile - this is an excerpt :
Code:
# For non-root users, add the current directory to the search path:
if [ ! "`id -u`" = "0" ]; then
 PATH="$PATH:."
fi
So the current working directory gets added to the path for non root users. The file also sets the default system path here :
Code:
# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
so /usr/local/bin is set in your path anyway. If you want to check this just run :
Code:
echo $PATH
to see what the path is set too. As has been said - files in the search path will execute, (if executable), without giving their directory to the command line.
 
Old 07-19-2009, 07:43 PM   #6
masonm
Senior Member
 
Registered: Mar 2003
Location: Following the white rabbit
Distribution: Slackware64 -current
Posts: 2,300

Rep: Reputation: 90
Yep, the magic word is PATH
 
Old 07-19-2009, 09:20 PM   #7
Bruce Hill
HCL Maintainer
 
Registered: Jun 2003
Location: McCalla, AL, USA
Distribution: Arch, Gentoo
Posts: 6,940

Rep: Reputation: 129Reputation: 129
And you don't even need the echo ... just $PATH

$PATH ... $PATH ... $PATH
 
Old 07-19-2009, 09:39 PM   #8
gmartin
Member
 
Registered: Mar 2003
Location: PA
Distribution: Slackware 13.37 Linux Reg # 341245
Posts: 285

Original Poster
Rep: Reputation: 40
Thanks, everyone. Learned something today - and that's good!
 
Old 07-19-2009, 11:00 PM   #9
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
And you don't even need the echo ... just $PATH
Hmm - I always add the echo but you're quite correct - it isn't neccesary. (Just an old habit I suppose)
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS lookup doesn't work, ping, firefox will not work properly lovemov Linux - Networking 2 04-23-2009 02:30 PM
can't make ethernet on laptop work, wireless and usb work fine ubuntu 8.10 rz1988 Linux - Newbie 10 01-13-2009 02:21 PM
Getting a touch screen to work, must get PCI serial device to work first sternocera Linux - Hardware 2 10-03-2008 06:23 AM
I have AD authentication work, how do i make SSH PAM work in RHEL4? epmd Red Hat 0 09-19-2007 06:04 PM
FALCONS EYE (nethack) FAILS ON STARTUP, use to work, wont work even after reinstall roorings Linux - Software 0 10-08-2003 10:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration