http://wiki.bash-hackers.org/scripting/style
It only works with functions, and it will delete all comments and empty lines. Shell expressions like $'\r' are interpreted as they should.
But it is still useful to quickly clean up some messy code:
- Copy all functions into a text file "messy-functions.txt":
- Code: Select all
getwddefs()
{
wddefs="0"
read -p "Download Microsoft Windows Defender definition files? [y/n] " addwddefs
if [ "$addwddefs" == "y" ]; then
wddefs="1"
param7="/wddefs"
fi
}
- Source that file:
- Code: Select all
$ source messy-functions.txt
- Display the function declarations with "type" or "declare -f". All functions will be pretty-printed by the shell itself. In this example, the indentation will be corrected to four spaces:
- Code: Select all
$ type getwddefs
getwddefs is a function
getwddefs ()
{
wddefs="0";
read -p "Download Microsoft Windows Defender definition files? [y/n] " addwddefs;
if [ "$addwddefs" == "y" ]; then
wddefs="1";
param7="/wddefs";
fi
}
$ declare -f getwddefs
getwddefs ()
{
wddefs="0";
read -p "Download Microsoft Windows Defender definition files? [y/n] " addwddefs;
if [ "$addwddefs" == "y" ]; then
wddefs="1";
param7="/wddefs";
fi
}
When in bash, do as the bash does.