* On 2023 26 Aug 11:10 -0500, Tom Browder wrote:
> On Sat, Aug 26, 2023 at 10:57 Greg Wooledge <g...@wooledge.org> wrote:
> 
> > On Sat, Aug 26, 2023 at 10:49:45AM -0500, Tom Browder wrote:
> > > I would like to know whether 'sudo -i' or 'sudo -s' was used.
> 
> ...
> 
> > In fact, I suspect "I need to know if the cwd is /root" is STILL an X-Y
> > problem.  It's sounding like "I need to ensure my script's working
> > directory is /foo".  If that's truly the case, just do "cd /foo || exit"
> > at the top of the script.
> 
> ...
> 
> Excellent mind-reading, Greg! So to use your line I will put in that dir:
> 
>     "cd /required-dir || exit"

In such cases I prefer specifying the complete paths in the script so as
not to get lost.  If the script needs to work in a specific directory of
root I'll put:

        cd /root/dir/dir1

or something like:

        cd /home/username/dir

and so on (adding whatever error recovery is needed).

If I need to source a file I just type in the complete path name.  It's
a one time bother and the executing shell doesn't care and as the script
gets more complex it's much easier to keep one's bearings on where the
script is working at various points.

As I see it, relative paths are more for interactive shell use.

- Nate

-- 
"The optimist proclaims that we live in the best of all
possible worlds.  The pessimist fears this is true."
Web: https://www.n0nb.us
Projects: https://github.com/N0NB
GPG fingerprint: 82D6 4F6B 0E67 CD41 F689 BBA6 FB2C 5130 D55A 8819

Attachment: signature.asc
Description: PGP signature

Reply via email to