"; */ ?>

Convert TABs to spaces using shell scripting

The purpose is simple and clear – to archive a “indentational independence“, when indentation is the same across all platforms, editors and systems.

Here is the simple shell script that takes the file as the command line argument and substitute all TABs with spaces:

#!/bin/sh

#
#   Script converts TABs to spaces in a given file
#

if [ $# -ne 1 ]; then
     echo 1>&2 "This script converts TABs to spaces in a given file
                \\n\\n\\tUsage: $0 "
     exit 127
fi

expand $1 > temp && mv temp $1

The above script shows how that it is all done by virtue of the “expand” command that does just that ;)

And no need to worry about sed‘s s/tab/space/g pattern, because “expand” does exactly what we need ;)