Escaping single quotes inside single quotes in bash

In bash, you can use the backslash character ("\") to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example:

alias ycd='some_command'

works fine but

alias ycd='command -option 'something''
alias ycd='command -option \'something\''

both of the above return errors.

A trick around this problem is to use both quotes i.e. use double quotes to surround the single quote and single quotes again to surround the single quote.

Changing keyboard on a mac

  1. Click on the Apple logo and select "System Preferences"
  2. Click on "International" icon on "System Preferences" window.
  3. Click on "Input Menu"
  4. Make sure that "Show input menu in menu bar" is checked.
  5. Make sure the "Keyboard Viewer" is set to viewable.
  6. Select the languages you desire
  7. Close the window
  8. Use the flag icon on the top left to set the keyboard layout

PHP code to convert XML to JSON

Converting XML to JSON is very easy in PHP. See the following code.

$jsonfile =  fopen("file.json", "w") or die ("Cannot open JSON file for writing");
$xml = simplexml_load_file("file.xml") or die ("Cannot load xml file");
fwrite($jsonfile, json_encode($xml));

line 1: open an empty file to write JSON line 2: load xml file line 3: convert xml to json using json_encode function and then write the json file line 4: close the file

Adding a directory to PATH in Mac

To see if a directory is in PATH:

$ echo $PATH

Note that directories are separated by : symbol. To add your directory to the path, edit your bash_profile:

$ vi ~/.bash_profile

Add the following line of code, assuming you want to add /usr/local/mysql/bin to the PATH

export PATH="/usr/local/mysql/bin:$PATH"

Save your changes. Close your terminal. Open a new terminal. Your directory should be in PATH

PHP package managers

PHP has seemingly countless extensions and packages. See to see the list of packages. Naturally, you would wish to have a software to manage the extensions and packages. Wish granted! PEAR, PECL, and composer are PHP package managers.


PEAR was the first PHP package manager. It is designed for systemwide packages so anytime you install a package through PEAR, it is installed in a central repository. The scripts and commands become available from anywhere on the commandline.


PECL manages compiled extensions to PHP.

Setting up virtual lamp stack on microsoft windows

Oracle's VirtualBox is a very solid and stable virtual machine but it isn't the simplest to work with. So I abandoned it a week after I started working with. Recently, I had to return. Why? Vagrant. It is a fantastic virtual machine workflow system. It is amazingly easy to use and deals with VirtualBox for you. On top of that there are many excellent stack available for free download from the Internet. Following is how I setup my LAMP stack.