Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    As a general rule, it is almost always better not to do this at all and instead pass the file as an argument when launching the script. That way, the command is repeatable and loggable and the user can take advantage of tab completion to find the file instead of needing to laboriously type it out which is both annoying and very error prone. Please consider rethinking this. Commented May 27, 2021 at 11:01
  • Also note that a single filename can be 255 bytes in most filesystems, and the maximum length of a path passed to a system call is 4096 (or 4095, or something like that). And while those are likely excessive, you never know what someone will want to do, so you shouldn't put up arbitrary limits. And if you're thinking about protecting against a user filling the system memory with a really huge input, then you need to do the limiting at read already, instead of first reading the data in and then checking the length after the fact. Commented May 27, 2021 at 11:41
  • 1
    Get out of the habit of using ALLCAPS variable names, leave those as reserved by the shell. One day you'll write PATH=something and then wonder why your script is broken. Commented May 27, 2021 at 12:06
  • 1
    Thanks everyone, I am very new to all this so all this is very helpful. Thank you :) Commented May 27, 2021 at 17:31