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.

3
  • 1
    This should be top answer. It's much safer to get basename command than to split by slashes and hope that there is no \/ in the filename Commented Mar 16, 2020 at 11:59
  • It basically introduces an arbitrary command execution vulnerability as you're not properly escaping the filename in the shell code that you generate in cmd. For instance, if you run awk '...that...' ./*.txt in a directory that contains a file called $(reboot).txt, it will reboot. Commented Sep 4, 2024 at 13:01
  • Also getline only reads the first line (well record, that's dependent on the value of RS) of the output of the command, so you'll only be getting the first line of the file name (for those file names that are made of several lines). Commented Sep 4, 2024 at 13:02