remember to test bash aliases

My linux vm reminded me of the importance of testing bash aliases before adding them to the .bash_aliases file.

This was the mistake:

alias local='git checkout local'

The next time I opened a terminal, I received this wonderful message:

bash: /etc/bash_completion.d/gdb: line 23: syntax error near unexpected token `('
bash: /etc/bash_completion.d/gdb: line 23: `            local path_array=( $(echo "$PATH" | sed 's/::\+/:/g;s/^:\|:$//g') )'
bash: /etc/bash_completion.d/vncviewer: line 92: syntax error near unexpected token `('
bash: /etc/bash_completion.d/vncviewer: line 92: `        local dash options=( \'

I had done several other things before opening the terminal, so I didn’t immediately recognize the alias as the culprit. The message just confused me more. The terminal still seemed to work properly.

Took some time, but I narrowed it down to that alias. Turns out that local is a bash builtin command and using it as an alias command is a syntax error. The message has to do with where the .bash_alias file is included and evaluated.

Here’s the main point of the post:

Always remember to test aliases before adding them to the .bash_aliases file. Check the man pages, google it, actually type it. I have been surprised several times by how many two- and three-letter commands that already exist while thinking of short aliases for common commands.

And read the bash reference manual. There will be a test on Tuesday.

About Evan Gates

Switching from Visual Studio and C# to vim and ruby.
This entry was posted in bash, oops and tagged , , , , . Bookmark the permalink.

Leave a Reply