Skip to main content

Don't Repeat Yourself in Bashrc

·31 words·1 min · Download pdf

A handy way to add a line in bashrc only if it doesn’t exist already:

LINE=“export DISPLAY=localhost:0.0” FILE=~/.bashrc grep -q “$LINE” “$FILE” || echo “$LINE” >> “$FILE” || source ~/.bashrc

Discussion