IFS is confusing...
sumbach opened this issue · 2 comments
sumbach commented
I've always struggled with understanding the particulars of IFS and word splitting, so I'd like to try to give beginners as much help with this as possible.
- I think the default value of IFS is space, tab, and newline.
- It might be helpful to link to Word splitting in the Bash manual in case readers need the details.
Deleted user commented
Do you still find it confusing?
sumbach commented
@bucaran Yes, definitely 😖
The idea of IFS and word-splitting isn't too complicated or difficult to understand, but the particulars are very tricky.
I opened this issue to try to prompt a conversation about how IFS to explain/teach IFS. My personal inclination would be to recommend IFS=""
then point people to particular solutions for common problems:
- BashFAQ/001: How can I read a file (data stream, variable) line-by-line (and/or field-by-field)?
- BashFAQ/005: How can I use array variables?
- BashFAQ/020: How can I find and safely handle file names containing newlines, spaces or both?
- BashFAQ/050: I'm trying to put a command in a variable, but the complex cases always fail!
- BashFAQ/067: How can I trim leading/trailing white space from one of my variables?
- BashFAQ/100: How do I do string manipulations in bash?