A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
Posts tagged bash
How to reset the bash IFS variable
Jul 9th
Here’s a quick tip for everyone. I was working on a one-liner today at work that involved parsing through a file with some data in it. The data had spaces in it which can cause problems with the default $IFS variable (Internal File Separator). nixCraft has an excellent tutorial on working with the $IFS variable.
Read the rest of this entry »
What do three “less than” (<<<) symbols mean in PHP?
Jul 2nd
I am a true believer in that the best ways to learn how to do anything is by studying work of those who have done the same thing previously. When programming, that means looking at others’ code and learning from what they do. However, don’t assume that everything someone else does is correct! What this means is that not only should you learn what to do from other peoples’ code, but you should also learn what not to do.
Read the rest of this entry »
How to append values to an array in bash
Feb 4th
Last week I was working on a bash script for a project at work. The script parsed through a log file with server load and disk usage statistics at regular intervals. The script was calculating the average CPU idle time, disk utilization, and disk usage for servers. After calculating the averages for each of these three metrics, I then proceeded to loop through all the lines in the file and create an array of all the times when the CPU idle time was below average, or the disk utilization or usage was above average.
Read the rest of this entry »
bash Scripting Cheat Sheet
Jun 28th
- If...then
- if [ expression ]
then
commands
fi - If..then...else
- if [ expression ]
then
commands
else
commands
fi - If..then...else If...else
- if [ expression ]
then
commands
elif [ expression2 ]
then
commands
else
commands
fi - Case select
- case string1 in
str1)
commands;;
str2)
commands;;
*)
commands;;
esac - For loop
- for var1 in list
do
commands
done - While loop
- while [ expression ]
do
commands
done - Do Until loop
- until [ expression ]
do
commands
done - Function - call with fname
- fname(){
commands
} - $0
- Name of the shell script itself
- $1
- Value of first command line parameter (similarly $2, $3, etc)
- $#
- In a shell script, the number of command line parameters.
- $*
- All of the command line parameters.
- varname=value
- Create a variable named varname with a value of value
Shell Scripts
Jun 19th
This page will house the Shell Scripts that I have developed. Shell scripts are run from a Linux Command-line or SSH interface.
Post to Twitter
Update your Twitter account from the shell
How to Post to Twitter from a Linux Shell
Jun 18th
I had a little downtime today at work and decided to write a shell script that I could use to tweet from the shell of my Linux server. The reason is that Twitter is one of many social networking sites that is blocked at my workplace. However, I do have access to my server and found a great one-liner on commandlinefu.com to update twitter via curl. I decided to expand on this a bit and wrote a shell script that offers a bit more than merely posting a tweet. Check out my shell script to post to Twitter here.
Linux Command-Line Cheat Sheet Posted
May 18th
I have posted today my Linux Command-Line Cheat Sheet. Unlike other Linux Cheat Sheets I have seen, I have created this one as more of a “targeted” cheat sheet. Instead of just containing various command-line commands, my cheat sheet focuses on providing tips/tricks for various Linux commands including common switches and options used with those commands, including grep, sed, find, tar, rpm, and more.
I have also included numerous shortcuts/key combinations for the vi/vim text editor. This may turn into it’s own cheat sheet in the near future if I continue to add to it due to the amount of info I have for vi alone. Time will tell.
Read the rest of this entry »

