Skip to content

Commit

Permalink
first version
Browse files Browse the repository at this point in the history
  • Loading branch information
gilcot committed May 29, 2017
1 parent 555691d commit 7dc91e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This a collection of scripts that could be a Ghist each.

During my _Unix_ course, this is one of the exercice I ask my students in
in order to start playing with `grep`:
"Using only grep, write a script that will extract from a given shell script,
after checking the file argument, all comments that start at firsh column."
"Write a script that will extract comment from a shell script. But make it
fail when the script is called with no argument, and also when the script
file cannot be found or read. Try to use only grep and keep your script the
smallest possible."

5 changes: 4 additions & 1 deletion get_comments
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# readable file requiered
grep -q "" "$1" || exit 1

# check first line
head -n 1 "$1" | grep -q '^#!/s\?bin/[a-z]*sh$' || exit 2

# extract comments
grep '^#' "$1" | cut -c 2-
grep -o '#.*$' "$1" | cut -c 2-

0 comments on commit 7dc91e0

Please sign in to comment.