Reading lines in a file and avoiding lines with # with Bash

后端 未结 10 2073
清歌不尽
清歌不尽 2020-12-03 06:47

I tried this:

file=\"myfile\"
while read -r line
do
    [[ $line = \\#* ]] && continue
    \"address=\\$line\\127.0.0.1\"
done < \"$file\"
         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 07:35

    [ "${line:0:1}" = "#" ] && continue
    

    This takes the string, gets the substring at offset 0, length 1:

    "${line:0:1}"
    

    and checks if it is equal to #

    = "#"
    

    and continues looping if so

    && continue
    

    http://www.tldp.org/LDP/abs/html/string-manipulation.html

提交回复
热议问题