Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Tuesday, June 28, 2011

Keyboard Number Pad Not Working

This is a very common thing to happen for Linux users using full blown keyboards (not a laptop). And it's caused mainly by a Linux accessibility feature, which allows you to use the arrows on your number pad as a mouse.

To revert back you have two simple options:

1- Hit "Ctrl+Shift+NumLock" on your keyboard

2- Disable the Mouse Keys feature on you keyboad configuration utility

 

Friday, June 24, 2011

Converting first characters to capital in a string variable - BASH

Let's say you have a variable that contains a string of text, and you need the first characters to be capitalized. This quick how to will show you just that.

My variable is set as follow:

$ var="this is a text title"

$ echo $var
this is a text title

 Bash has built-in variable substitution that will convert a matching pattern (see the man page for either bash or bash-bultins for more info).

${parameter^pattern}
${parameter^^pattern}

Here's a simplified usage:

$ var=test

$ echo ${var^t} # Could also be ${var^}
Test

 So for my first example, we can add the same parameter substitution to a for loop, and here's what we get:

$ var="this is a text title"
 
$ echo $var
this is a text title
 
$ for i in `echo $var` ; do echo ${i^} ; done | tr '\n' ' ' ; echo -e "\r"
This Is A Text Title