Date: Mon, 7 Jan 2008 10:50:47 -0600 From: Erik Osterholm <freebsd-lists-erik@erikosterholm.org> To: Steve Franks <stevefranks@ieee.org> Cc: User Questions <freebsd-questions@freebsd.org> Subject: Re: home dir executable (!/bin/sh, chmod+x) shell scripts won't run without "sh <script>" Message-ID: <20080107165047.GA12249@aleph.cepheid.org> In-Reply-To: <539c60b90801070813h537451e8q9264897bc9404260@mail.gmail.com> References: <539c60b90801070752l3d0e571cq8f7b1b519e1e808c@mail.gmail.com> <5D884B59-3CEF-4F81-B35D-4E54F5D6301C@gmail.com> <539c60b90801070813h537451e8q9264897bc9404260@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 07, 2008 at 09:13:39AM -0700, Steve Franks wrote: > > This is a sort of 'don't shoot yourself in the foot' design. You > > cannot run a script or binary simply by name if you're cwd is the > > directory that contains that script or binary. IIRC, you can't cd / > > usr/bin and run anything in /usr/bin without explicitly calling that > > file with the ./ telling the system THIS ONE. > > Ah! You'd think any one of the many tutorials I read would have > mentioned that little detail ;) > > Thanks, all > Steve You should search your tutorials for the PATH environment variable. In an over-simplified nutshell, when you type a command in your shell, it checks a number of different locations for the place to find the command you're trying to execute. Some of those locations are every directory specified in your PATH variable. My PATH is: /bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin This means that when I type 'ls', the shell looks for an executable named 'ls' in each of those directories (actually, it probably stops right after /bin/ls, since that's the correct one.) If the shell does not find a valid executable in the path, it will say that there is no such file or directory. In this case, you would try specifying the full path by typing /bin/ls, or /home/user/scriptname. '.' and '..' have special meanings--current directory and next-directory-up, specifically--so if your current working directory is /home/user, typing ./scriptname will be largely equivalent to typing /home/user/scriptname. ../scriptname would be largely equivalent to /home/scriptname. This is why some people suggested trying ./scriptname in other e-mails in this thread. The '.' notation for the current working directory enables you to add the current directory you happen to be in as part of your path (thus making it searched when executing a command), however this has serious security implciations, so if you think that it's something you really want to do, you'll have to find out from someone else how to do it. erik
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080107165047.GA12249>