Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # When ${@} =~ ${COMMENTREGEX} is tested, it appears to loop for each match?
- ignore_comments(){
- if [ -z "${COMMENTREGEX}" ]; then
- COMMENTREGEX='^\s*#.*'
- fi
- echo "Whole line after: ${@}"
- if [[ ${@} =~ ${COMMENTREGEX} ]]; then
- printf "Ignoring: %s, commented out\n" ${@}
- else
- return 1
- fi
- }
- while IFS='' read -r line || [[ -n "${line}" ]]; do
- echo "Whole line before: ${line}"
- if ignore_comments "${line}"; then
- echo "${line}"
- fi
- done < /export/home/alfie/Documents/scripts/bash/test_file
- # test_file
- line1 word2 word3 word4
- # This is a comment
- #another
- line2
- line3
- # Output ./test_loop
- Whole line before: line1 word2 word3 word4
- Whole line after: line1 word2 word3 word4
- Whole line before: # This is a comment
- Whole line after: # This is a comment
- Ignoring: #, commented out
- Ignoring: This, commented out
- Ignoring: is, commented out
- Ignoring: a, commented out
- Ignoring: comment, commented out
- # This is a comment
- Whole line before: #another
- Whole line after: #another
- Ignoring: #another, commented out
- #another
- Whole line before: line2
- Whole line after: line2
- Whole line before: line3
- Whole line after: line3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement