LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2021, 08:16 PM   #16
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,801

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550

Quote:
Originally Posted by igadoter View Post
Hi, I today tested some simple scripts and noticed something I don't understand. Say
Code:
. file
works fine in $HOME directory. I mean if script is called in $HOME as working directory. However I have to put prefix
Code:
. ./file
to make script works outside $HOME. If I don't do that I get error 'file not found'. That's a mess.
Then ${HOME} is in your PATH. Wherever you're trying to source it where you've found that a "./" prefix makes it work is obviously not in your PATH.

One workaround is to add ":." to the end of your PATH variable (and re-exporting it). That way, every directory on the system is potentially a location of executable and sourceable files when you're in the directory. However this is typically frowned upon for security reasons. (I'm not certain that those reasons makes much sense any more, though.) Finally, as was pointed out in by another responder, using full path names in program names and files in scripts is best. The time spent typing them in is far shorter than the time it takes debugging "file not found" messages.

Style note: when sourcing files in a script, it's often preferable to use "source" instead of ".". It's easy to miss a single "." in a script.

Good luck...
 
  


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
Is it possible when posting in bbs dot archlinux dot org there is no way to attach text? stf92 Arch 2 07-19-2018 08:19 PM
what's that dot command in bash scripts? stabu Linux - Software 4 12-07-2006 11:33 AM
dot space dot binary_0011 Linux - Newbie 5 09-14-2006 07:43 AM
useradd not accepting dot so i am not able to use dot in mail id hanu_raob Linux - General 5 05-13-2004 07:04 AM
dot and dot dot gag Linux - Newbie 4 10-17-2003 05:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:19 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