Write a bash script to indent code blocks in a bash source file.
Conditions:
The source file will contain only printing characters, spaces, and newlines.
The source file will contain only valid bash code. It is not necessary to check for invalid input.
The source file will not contain function declarations.
The source file may contain random indentation.
The source file may contain nested blocks.
In the source file keywords while/until/for/case/if/done/esac/elif/else/fi will be the first words on a line and will not be quoted.
Requirements:
Read from standard input, write to standard output.
Lines inside a while/until/for block should indented two spaces. If the block's done is the first word on a line it should begin in the same column as the while/until/for .
Lines inside a case block should indented two spaces. If the block's esac is the first word on a line it should begin in the same column as the case .
Lines inside an if block should indented two spaces. If the block's elif/else/fi is the first word on a line it should begin in the same column as the if .
Lines with # in the first column should not be indented.
Lines not inside any block should not be indented.
Be sure your program includes all of the following:
comments with your name, the date, and the assignment
comments with instructions for using the program
descriptive names and/or comments explaining variables & functions
indentation of code blocks
comments explaining any non-obvious control flow
The program is due Tuesday May 17 at midnight. Submit your program by email on our class server with:
mail -s 'assignment 1' stuart < source-file
where source-file is the name of your program file.
Hints:
work on the simplest cases first
think about the structure of your data and logic before you write any code
start with the smallest possible amount of code
make sure your existing code works before adding new code
add the smallest possible amount of new code, then test again
output variable values, loop counts, etc. for debugging
test your code with a variety of inputs
anticipate error conditions and handle them gracefully.