Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions bash/bf.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@ die()
exit 1
}

if (( $# )); then
if [[ -e $1 ]]; then
program=$(< "$1")
# program comes from -c flag
program=''
while getopts 'c:' flag; do
case $flag in
c)
program=$OPTARG
;;
'?')
exit 1 # usage error occured, and bash printed a diagnostic
;;
esac
done

if test -z "$program"; then # corner case: -c '' gets here
if (( $# )); then
# program comes from filename argument
if [[ -e $1 ]]; then
program=$(< "$1")
else
die "file '$1' does not exist"
fi
else
die "file '$1' does not exist"
# program comes from stdin
mapfile -t
program=${MAPFILE[*]}
fi
else
mapfile -t
program=${MAPFILE[*]}
fi

program=${program//[^'><+-.,[]']}
Expand Down