-1

I source a file each day - is it dangerous by means of filling up the disk drive (if something is written anywhere)?

Someone once criticized me here in StackExchange for sourcing a file each minute (something I no longer do), I think it was something like "you are creating the file each minute!"

I'm not sure exactly, but even if I do it daily, is there any danger in this, by means of disk space? If so, what approach you'll take to protect the environment from such damage?

  • 1
    Please [edit] your question, and specify which command are you running – Yaron Feb 14 '18 at 12:33
  • 5
    What? Sourcing a file won’t write anything to disk in and of itself. – Stephen Kitt Feb 14 '18 at 12:37
  • ... in which case, sourcing the same file each minute or each day is useless (and possibly harmful). You only want to source a file when it changes (or when you first log in to the system). You also have to be careful to e.g. avoid extending a variable's value every time you source it (think PATH=/foo/bar:$PATH). – NickD Feb 14 '18 at 12:47

1 Answers1

4

No, sourcing a file or running a script daily, hourly or even every minute, is in itself not "dangerous", but it depends on what the script is doing.

For example, a script that creates temporary files, fills them with data and does not clean up after itself will, eventually, fill up a partition.

A file that modifies environment variables may blindly add values to e.g. PATH without testing whether those values are not already part of $PATH. Eventually, such a script would make it difficult to execute utilities on the command line if it was sourced many many times (the length of the command line plus the length of all environment variables and their values is limited to a particular value).

Some disk media is susceptible to wear, and some users go to great lengths to not write things to the physical disk (mounting filesystems in RAM, turning off write access on as many other mount points as possible etc). On such systems, the act of creating a file every minute may be considered less good (possibly depending on the size of the file)

The take-home message here is this: Sourcing or running a script often is not bad practice, depending on what it does. Making sure that scripts that you write does proper cleaning up and are able to detect when it's appropriate to make certain modifications is also good practice.

Kusalananda
  • 333,661