Browse Source

Always use 'raw' with read builtin

Turns out that read without params supports backslash escaping; that is,
`\t` gets translated to tab and `\` at the end of line connects with
next line.  Such feature is dangerous as implicit; read should almost
never be used without this parameter.

See [Bash Hackers wiki]1] for more.

  [1]: http://wiki.bash-hackers.org/commands/builtin/read#read_without_-r
Alois Mahdal 9 years ago
parent
commit
707991419b
1 changed files with 6 additions and 6 deletions
  1. 6
    6
      src/include/inigrep.sh

+ 6
- 6
src/include/inigrep.sh View File

43
     #
43
     #
44
     # In listing mode, prints *key names* instead
44
     # In listing mode, prints *key names* instead
45
     #
45
     #
46
-    while IFS= read line;                           # '  key  =  val  '
46
+    while IFS= read -r line;                        # '  key  =  val  '
47
     do
47
     do
48
         line="${line##*([[:space:]])}"              # line='key  =  val  '
48
         line="${line##*([[:space:]])}"              # line='key  =  val  '
49
         key="${line%%*([[:space:]])=*}"             # key='key'
49
         key="${line%%*([[:space:]])=*}"             # key='key'
65
     local sct_ok=false
65
     local sct_ok=false
66
     local sct_name
66
     local sct_name
67
     local line
67
     local line
68
-    while IFS= read line;
68
+    while IFS= read -r line;
69
     do
69
     do
70
         if [[ $line =~ ^[[:space:]]*\[[^]]*\].* ]];     # IOW: 'spaces[name]anything'
70
         if [[ $line =~ ^[[:space:]]*\[[^]]*\].* ]];     # IOW: 'spaces[name]anything'
71
         then
71
         then
95
     # Filter only section/keys/path names from the stream
95
     # Filter only section/keys/path names from the stream
96
     #
96
     #
97
     local key="__NOKEY__" line="" sct="__NOSCT__"
97
     local key="__NOKEY__" line="" sct="__NOSCT__"
98
-    while read line;
98
+    while read -r line;
99
     do
99
     do
100
         case "$line" in
100
         case "$line" in
101
             \[*\]) sct=${line#[}; sct=${sct%]}; key=__NOKEY__     ;;
101
             \[*\]) sct=${line#[}; sct=${sct%]}; key=__NOKEY__     ;;
124
     #
124
     #
125
     local path
125
     local path
126
     debug -v strategy
126
     debug -v strategy
127
-    while read path;
127
+    while read -r path;
128
     do
128
     do
129
         test -f "$path" || continue
129
         test -f "$path" || continue
130
         case $strategy in
130
         case $strategy in
158
             debug -v FFOO_INIGREP_PATH
158
             debug -v FFOO_INIGREP_PATH
159
             echos "$FFOO_INIGREP_PATH" \
159
             echos "$FFOO_INIGREP_PATH" \
160
               | tr ':' '\n' \
160
               | tr ':' '\n' \
161
-              | while read trydir;
161
+              | while read -r trydir;
162
                 do
162
                 do
163
                     test -n "$trydir" || continue
163
                     test -n "$trydir" || continue
164
                     trypath="$trydir/$arg"
164
                     trypath="$trydir/$arg"
341
     #
341
     #
342
     local idx=0     # current item index (zero-based)
342
     local idx=0     # current item index (zero-based)
343
     local path
343
     local path
344
-    while read path;
344
+    while read -r path;
345
     do
345
     do
346
         test -z "$path" && continue
346
         test -z "$path" && continue
347
         test $idx -gt 0 && echo -n ':'
347
         test $idx -gt 0 && echo -n ':'