bash - About getopts function -


i'm again :( still problem bash, question make script read option -r further further operation. think make right when tried run it, got feedback saying:" ./stripchars: line 20: -r: no such file or directory". , 1 saying:" ./stripchars: line 26: ne: command not found" here code:

#!/bin/bash file=$1 while getopts "r:" o; case "${o}" in     r)         r=${optarg}         ;;     *)         ;; esac done shift $((optind-1)) if [ ! -z "$file" ] exec 0< "$file" fi while ifs='' read -r line echo "$line" | tr -d '${r}' done if [ -z "${r}" ] if [ ! -z "$file" ]     exec 0< "$file" fi while ifs='' read -r line         echo "$line" | tr -d '[:punct:]'     done fi 

if file name first argument (as implied file=$1), getopts has non-zero exit status immediately (since first argument not option), , never enter loop. need change call like

myscript -r whatever foo.txt 

and move file=$1 after loop parses options.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -