#!/usr/bin/env bash # Appends text to a file (unless the text is already there). This avoids # duplicating lines when the container is rebuilt, since the container's file # system is persisted on the host beyond the life of the container function append_line_once() { if [[ "$#" -ne 2 ]]; echo "`append_line_once` expects 2 args (text, file)" exit 1 fi text="$1" file="$2" declare -i num_matches="$(wc -l "$(grep "$text" "$file")")" if [[ "$num_matches" -eq 0 ]]; then echo "$text" >> "$HOME/.bashrc" fi } append_path_cmd="export PATH=\$PATH:$HOME/.local/bin" declare -i num_append_path_cmds="$(wc -l "$(grep "$append_path_cmd")")" if [[ "$num_append_path_cmds" -eq 0 ]]; then echo "$append_path_cmd" >> "$HOME/.bashrc" fi