COMS C171 Dvc Diablo Valley College Bash Program Project

Assignment 3

Bash Program

Write a bash program to align the comments in bash source file.

Comments start with an unquoted # which begins a word and end with a newline.
handling quotes is optional and complex – do this last for extra credit
lines without comments should not be changed
lines which begin with # should not be changed
other lines containing comments should have the comments moved
all comments should begin in the same column
2 columns after the end of the longest code (before comments)
example input
# begins with #
# begins with space
A=(foo bar)
B=(bax qux) # comment
C=(aaa bbb) # don't change indentation
echo ${#A[@]} # first # doesn't begin a word
echo " # not a comment"
echo " # comment""
echo \"" # not a comment\""
example output
# begins with #
# begins with space
A=(foo bar)
B=(bax qux) # comment
C=(aaa bbb) # don't change indentation
echo ${#A[@]} # first # doesn't begin a word
echo "" # not a comment""
echo "" # comment""
echo \"" # not a comment\""

Requirements

Use only bash and standard UNIX utilities:
do not use awk or other UNIX programming languages
Read from standard input