Bashing The Bash!
February 23, 2022 Leave a comment
A longish read β¦your call.
Well, the title should not indulge you in thinking in terms of “a fanboy’s story”. Because, I am NOT a one, in that sense. I am a technologist and my viewpoints should be neutral and revolve around wholely and solely based on technology offering and understanding.
Alright! As the alarm or heads up in the above paragraph passed, let’s focus on the materials at hand. In this post, I am sticking my neck to provide information about my work environment which revolves around bash and the steps to produce it.
I have picked up bash as my default shell, which is basically no brainier or mere coincident, but just because this is the default one on most of the GNU/Linux systems. So, having it and sticking around with it helps me get along with the system much smoother way. Every other shell has merits and demerits, the same way, this one is no exception.
The good part is that living with it (in fact 90 percent of the time) forces me to bring out the best in it, and also it compels me to see the ugly side too.
The initialization scripts are pretty straightforward forward but when you deep dive and do some scripting, sooner rather than later it quickly gets very complicated and the syntax becomes quite arcane.
But, I had to put some effort into getting along with it. Once you choose something to live on for a long time, you need to put an effort to keep it thriving, like in other serious factors/relations in life. So, on the quest for that, I have developed a love-hate relationship with. Sometimes bash-related stuff makes life so easy and achievable so easily, on the other hand, it handicaps achieving something beyond a certain point. That is probably not Bash’s fault and certainly mine.
Like everyone else, I too fiddle with it initially for not-so-serious or impactful tasks/work on the system. It is driven by two factors, lack of understanding (it is considerably reduced but not gone, and from time to time I am prone to falter or stuck). Anyway, I have come to terms with it and am enjoying whatever little thing I can achieve with it.
I do all my configuration tweaks with it by writing small, independent scripts and then stitching them together to achieve whatever I wanted to achieve. That is the predominant methodology to get along with it. Another reason, I absolutely loathe writing gigantic code bases for something trivial to achieve. To, achieve more out-of-ordinary stuff, I break down problems into smaller pieces and develop each individual piece, and then try to amalgamate all the parts.
I have a public repo uploaded on github, if you haven’t noticed it yet, here is the link to it Scripts repo on GITHUB . I am certainly not claiming everything in that repo is pleasant, but those tidbits work for me. Quite a few of them were borrowed over the years from better people and I have heavily tweaked them to suit my need. Some of them were written by me to fix the damn environment and enhancement from scratch. Some of them I keep it as it is, as those don’t need any improvement for my liking.
I have learned to do it better way(reading to fix my problem) by looking at them and trying to read from their perspective. It is very important to write pieces of code to get your understanding clear, but it is hugely important to read more stuff from others can certainly boost the understanding. Fixing stuff mentioned in the other script can be very educative and alleviate the learning curve. Never mind the trouble, it is the same with every other thing you are putting your hands on.
Thankfully, the internet has its upside, when you stumble upon good resources, which is/were shared by better people and it is free to grab. I have been benefiting like that grandly. And importantly, I am trying to give favor back to the medium for others’ benefit. Sometimes my frivolous work helps others and sometimes they are annoyed by the way I present the stuff. But, that is okay, people are entitled to their opinions.
Now, there are plenty of resources to be found on the internet, not every one of them is good but few are really good. I will provide you some resources at the end of this article for your inspections.
Here is my .bashrc file for bash shell intialization environment . You can take a peek at it.
Here it is entirely for the impatience :
#!/usr/bin/env bash # Author: Bhaskar Chowdhury # Email: unixbhaskar@gmail.com # Website : https://github.com/unixbhaskar # Check for existence of global bashrc if [[ -e /etc/bashrc || -e /etc/bash.bashrc ]]; then source /etc/bashrc || source /etc/bash.bashrc fi # Bunch of exports LESSOPEN="|/home/bhaskar/bin/lesspipe.sh %s"; export LESSOPEN export PATH="$PATH:/home/bhaskar/bin" #export PILOTRATE=115200 test -s ~/.alias && . ~/.alias || true export HISTTIMEFORMAT="%h/%d/%Y - %H:%M:%S " export HISTFILESIZE=99999 export HISTSIZE=99999 # Aliases alias ls="ls --color=always" alias grep="grep --color" shopt -s checkwinsize cdspell autocd direxpand dirspell dotglob globstar histappend alias mount="mount | column -t" alias ports='netstat -tulanp' alias meminfo='free -m -l -t' alias psmemhog='ps auxf | sort -nr -k 4' alias pscpuhog='ps auxf | sort -nr -k 3' alias fetch='wget -c' alias rsync='rsync --progress --stats -ravz' alias c="clear" alias d='cd ~/Downloads' alias p='cd ~/Pictures' alias linuxgit='cd ~/git-linux/linux/' alias boot='cd /boot' alias music='cd ~/Music' alias admscripts='cd ~/Adm_scripts' alias docu='cd ~/Documents' alias dstat='dstat -afv' alias root="sudo su -" alias sstatus="sudo systemctl status" alias srestart="sudo systemctl restart" alias diskinfo="df -h" alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers' alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers' alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers' alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers' alias vpn_start='sudo /home/bhaskar/vpn_connect' alias dmesg='sudo dmesg -H -T' alias logs="find /var/log -type f -exec file {} \; | grep 'text' | cut -d' ' -f1 | sed -e's/:$//g' | grep -v '[0-9]
I have cut short the file output here. This file has grown over the years, added, collected, removed, and rewritten many times in the past to make exactly what I want the environment should be.
Now, time for some resources, which I have referred to above somewhere.
- BASH Frequently Asked Questions
- GNU Bash manual
- How-to: Bash Keyboard Shortcuts
- Explain Shell Commands
I hope this will help.