Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I have been writing shell scripts for over twenty years and don't think I have ever encountered a file name with a newline. I have hit file names starting with a dash - though being interpreted as flags at least a few times. Every command should support the -- path separation feature a lot of newer stuff like git does.


Every command should support the -- path separation feature a lot of newer stuff like git does.

That's a POSIX standard feature:

https://pubs.opengroup.org/onlinepubs/009696799/basedefs/xbd...

The argument -- should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character. The -- argument should not be used as an option or as an operand.


I don't place newlines in my filenames, but I also prefer my shell scripts to be portable.

Learning and understanding the bash oddities is key for me because I use it so often. It's the same reason I quote every expansion; sure my text likely doesn't have spaces, but maybe it does and id rather use the extra quote characters to ensure I don't have to troubleshoot language grammar bugs in my code


I stopped having to proactively learn most gotchas by just having the spectacularly useful shellcheck linter automatically run on save.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: