Skip to content

Instantly share code, notes, and snippets.

@RupGautam
Created December 6, 2017 06:39
Show Gist options
  • Select an option

  • Save RupGautam/093d50e47471ff499b669c821639a777 to your computer and use it in GitHub Desktop.

Select an option

Save RupGautam/093d50e47471ff499b669c821639a777 to your computer and use it in GitHub Desktop.
#!/bin/bash
CMD_LINE_USAGE="Usage: $0 [-h] [-f file] [-r report]"
NUM_ARGS=1
function show_help() {
echo "${CMD_LINE_USAGE}"
echo "Options are:"
echo " -h for help"
echo " -f specify a file"
echo " -r generate report"
}
function parse_file() {
filename=$1
if [[ -e "$filename" ]]; then
echo "${filename}" | awk -F"." '{print $1}' | awk -F"_" '{print $NF}'
exit 1
fi
}
function parse_assignment_file() {
filename=$(parse_file)
echo "Enter a file name: "
read filename
if [ -z "filename" ] then
exit
fi
terminal=`tty`
exec < $filename
count=1
while read line ; do
echo $count.$line
count=`expr $count + 1`
done
exec < $terminal
}
while getopts "hl:f:c" opt; do
case "$opt" in
h) show_help
exit 0
;;
c) parse_assignment_file=$(parse_assignment_file ${OPTARG})
;;
f) parsed_file=$(parse_file ${OPTARG})
;;
l) just_loop
;;
esac
done
echo ${parsed_file}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment