This is how I add multiple aliases to /etc/bash.bashrc
:
cat <<-"BASHRC" >> /etc/bash.bashrc
alias rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service"
alias brc="nano /etc/bash.bashrc"
alias www="cd /var/www/html"
alias imb="bash /opt/imb.sh"
alias nwsm="bash /opt/nwsm.sh"
BASHRC
source /etc/bash.bashrc
I feel I could pass on the heredocument and use some other way that would also check if the aliases are already there, is there a simple solution for that?
You may use grep
to check if the line exists, before adding it to /etc/bash.bashrc
.
#!/bin/bash
cat > /tmp/aliases.tmp << 'BASHRC'
alias rss='/etc/init.d/php*-fpm restart && systemctl restart nginx.service'
alias brc='nano /etc/bash.bashrc'
alias www='cd /var/www/html'
alias imb='bash /opt/imb.sh'
alias nwsm='bash /opt/nwsm.sh'
BASHRC
for i in `cat /tmp/aliases.tmp`; do
[[ grep "$i" /etc/bash.bashrc ]] || echo "$i" >> /etc/bash.bashrc
rm /tmp/aliases.tmp
source /etc/bash.bashrc
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments