The internal field separator (abbreviated IFS) refers to a variable which defines the character or characters used to separate a pattern into tokens for some operations. IFS typically includes the space, tab, and the newline.
Show my current IFS:
echo -n "$IFS" |xxd
00000000: 2009 0a
Now I wrote a simple bash script.
The whole code is located in my dropbox.
When I paste it into the console:
At the beginning of line 2 till line 5, it is \t
; if I replace it with a blank, it can be copied into console and nothing happens.
So we can conclude that \t
results in this action. I wonder, if the variable $1
has never been assigned to, how is the code running when pasting into the console?
I've read the IFS
concept several times, but can't find an explanation.
This is because when you paste something, the behaviour is as if you entered it literally; because you use tabs for indentation, pasting triggers autocompletion.
There is a readline setting to avoid that:
set enable-bracketed-paste on
This goes into your .inputrc
.
From the manual:
When set to
On
, Readline will configure the terminal in a way that will enable it to insert each paste into the editing buffer as a single string of characters, instead of treating each character as if it had been read from the keyboard. This can prevent pasted characters from being interpreted as editing commands. The default isoff
.