Skip to main content
Tweeted twitter.com/StackUnix/status/964159751167926272
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link
dot
  • 755
  • 5
  • 12
  • 23

bash script: incorrect argument value being set

Problem

I have a script that accepts a few different (optional) command line arguments. For one particular argument, I'm getting the value "less" appear but I don't know why.

Bash Code

while getopts ":d:f:p:e:" o; do
  case "${o}" in
        d)
            SDOMAIN=${OPTARG}
            ;;
        f)
            FROM=${OPTARG}
            ;;
        p)
            PAGER=${OPTARG}
            ;; 
        e)
            DESTEXT=${OPTARG}
            ;;                       
        *)
            show_usage
            ;;          
    esac
done

source "./utils.sh"
test #test includes

echo "$SDOMAIN is the sdomain"
echo "$FROM is the from"
echo "$PAGER is the pager"
echo "$DESTEXT is the extension"

exit

Output

When I run my script, this is what I see:

lab-1:/tmp/jj# bash mssp.sh -d testdomain.net         
Utils include worked!                                       
testdomain.net is the sdomain                                               
 is the from                                                                    
less is the pager                                                               
 is the extension                                 

I can't see why I'm getting the "less" value in pager. I was hoping to see empty string. If you can see my bug, please let me know. I've been looking at this too long.