Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 699 Bytes

bash.md

File metadata and controls

59 lines (42 loc) · 699 Bytes

bash

add a line to a file if it does not exist

function write_line_to_file() {
    if [[ ! -n "$(cat "$2" | grep "$1")" ]]
    then
        echo "${1}" | tee -a "${2}" > /dev/null
    fi
}

write_line_to_file 'line to write' "/path/to/file"

heredoc

multi-line to file with var

VAR="baz"
cat <<EOF | tee ${path_to_file}
foo
bar
${VAR}
EOF

looping

while

input="/path/to/file"

while IFS= read -r line; do
  echo "${line}"
done <"${input}"

netstat

netstat -tulpn

read lines from a config file ignoring comments

grep -v "^\s*${comment_char}"

testing

network latency

sar -n TCP,ETCP 1