# How to compare a command line parameter with -- in shell scripting

**URL:** <https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985>\
**Category:** Shell Programming and Scripting\
**Created:** [July 20, 2009, 7:52am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985 "2009-07-20T07:52:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![padmisri](https://community.unix.com/letter_avatar/padmisri/32/5_5575768a8748004e209b776fc1b2916d.png) [@padmisri](https://community.unix.com/u/padmisri)\
**Post date:** [July 20, 2009, 7:52am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985/1 "2009-07-20T07:52:29Z")

</div>

Hi,

I need to check if a parameter provided at the command line is equal to --.How can i do that ? Please help me.

Thanks and Regards,  
Padmini

---

<div class="post-metadata">

**Author:** ![ranjithpr](https://community.unix.com/letter_avatar/ranjithpr/32/5_5575768a8748004e209b776fc1b2916d.png) [@ranjithpr](https://community.unix.com/u/ranjithpr)\
**Post date:** [July 20, 2009, 8:10am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985/2 "2009-07-20T08:10:51Z")

</div>

Did you mean

```nohighlight
if ["$1" = "--"]
then
  echo Matching with --
else
  echo Not matching with --
fi

```

---

<div class="post-metadata">

**Author:** ![padmisri](https://community.unix.com/letter_avatar/padmisri/32/5_5575768a8748004e209b776fc1b2916d.png) [@padmisri](https://community.unix.com/u/padmisri)\
**Post date:** [July 20, 2009, 8:20am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985/3 "2009-07-20T08:20:55Z")

</div>

yes but am actually accessing the arguments with the arg variable in a for loop.so how can i compare the value of the arg variable with "--"

---

<div class="post-metadata">

**Author:** ![ranjithpr](https://community.unix.com/letter_avatar/ranjithpr/32/5_5575768a8748004e209b776fc1b2916d.png) [@ranjithpr](https://community.unix.com/u/ranjithpr)\
**Post date:** [July 20, 2009, 8:43am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985/4 "2009-07-20T08:43:02Z")

</div>

Still I am not clear, if you want to compare value of variable 'args' with '--'. It can be done like below

```nohighlight
if ["$args" = "--"]
then
  echo Matching with --
else
  echo Not matching with --
fi

```

---

<div class="post-metadata">

**Author:** ![kshji](https://community.unix.com/user_avatar/community.unix.com/kshji/32/15661_2.png) [@kshji](https://community.unix.com/u/kshji)\
**Post date:** [July 20, 2009, 8:44am UTC](https://community.unix.com/t/how-to-compare-a-command-line-parameter-with-in-shell-scripting/244985/5 "2009-07-20T08:44:22Z")

</div>

```nohighlight
#!/bin/yoursh

usage()
{
   cat <<EOF >&2
   hello world
EOF
}

## main ##

flag1=""
while [$# -gt 0] 
do 
     arg="$1" 
     case "$arg" in 
            -d) flag1="$2"; shift ;; 
            --) shift; break ;;
            -*) usage ;; 
            *) break ;; # - interrupt this loop, this is argument, not option
     esac
     shift
done

# now you can handle arguments using while or for
for arg in $*
do
    yep "$arg"
done

```
