Recently I encountered a problem where I had to create couple of arrays in bash and these were quite dynamic in nature. This script was supposed to be used by couple of guys whom I did not trust too much in opening the script and modifyikng the array. So, the solution was to put these in different files and then put them in array using bash script itself. This is when I went through the bash man page again and found an interesting new inbuilt mapfile
The use of this command is very simple
mapfile -t <array_name> < <filename>
This made my life so simple. Now all I had to do was put all these values for arrays in different files and use the mapfile in the bash script and tell the users to just modify the files and no need to touch or modify the script.
Sometimes, some small things that we don’t actually think can be useful are such useful. I faced this couple of days back when I was working on something and the amount of logs getting generated and the files getting rotated was too fast. If I had to use this for sometime, I needed some script, application or something to make sure that the logs are zipped every few seconds. Finding an application for this would take time and what good is bash if we need to find applications for this. So, a simple bash command did the trick. Most of us would know this but applying it and using it at the right time, was what saved my life. Thanks to bash. Here is the command:
for i in *.log
Can it get simpler than this 🙂
A Guest Post by David Cleland from TotalApps.
In 2006 I proudly started my first blog, DigMo! It was technology, it was creativity, it was music and it was education. Despite it being a bit of blog soup I was pleased at how quick the site grew but within a few years it reached a critical point beyond which I really couldn’t get the traffic to grow. The site was frankly far too general to appeal to a specific community.
Read more @ http://feedproxy.google.com/~r/ProbloggerHelpingBloggersEarnMoney/~3/_1BICnhtmwg/