#!/bin/bash if [ $# -eq 0 ]; then exit 1; fi function exists { if [ -e "$1" ]; then echo "WORD2TEXT - Error: '$txt' already exists." return 0 else return 1 fi } for arg; do case $arg in -) if [ -w "$PWD" ] then doc=".word2text.doc" #cat>"$doc" > "$doc" txt="" fi;; *) dir=`dirname "$arg"` if [ "$dir" == "" ]; then dir=$PWD; fi if [ -f "$arg" -a -w "$dir" ] then doc=$arg txt="${arg%doc}txt" fi;; esac while exists "$txt" || [ "$txt" == "" ]; do echo "WORD2TEXT - please, rename your converted document: " read txt done antiword -t "$doc" > "$txt" 2> /dev/null || ( echo "Error: The document you provided is not a Word document." > /dev/stderr rm "$txt") done