A Scripter's Notes

Emacs, scripting and anything text oriented.

Posts in “Unix”

Check If a Command Exists from Shell Script

I often need to check if a particular executable is present in the PATH before I can proceed with what I am doing in a shell script. Also I need to work with both tcsh and bash scripts. Below presents the different solutions that have worked for these shell scripts for me.

Second Argument to basename

It is quite common knowledge that the basename command is used to get just the file name without its full path.

> basename /home/$USER/file.txt
file.txt

But what wasn’t common knowledge, at least to me, was that basename also accepts a second argument ..

Using sed

sed stands for stream editor.

This is the most common way of my sed usage:

echo [SOMETHING] | sed 's/old/NEW/g'


Full Category Index →