# Need help in option parser

**URL:** <https://www.ruby-forum.com/t/need-help-in-option-parser/134561>\
**Category:** Ruby\
**Created:** [April 12, 2008, 1:04am UTC](https://www.ruby-forum.com/t/need-help-in-option-parser/134561 "2008-04-12T01:04:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kgoh](https://www.ruby-forum.com/u/kgoh)\
**Post date:** [April 12, 2008, 1:04am UTC](https://www.ruby-forum.com/t/need-help-in-option-parser/134561/1 "2008-04-12T01:04:40Z")

</div>

I am using optionparser to take in arguement. However, it seems like the  
option parser does not accept “&” “|” “\<” “\>” as the arguement when they  
are entered from the command line.

For example, I use opts.on("-d option"), when I enter -d 1&2 in the  
command line, it will only accept 1 in this case.

May I know what is the reason for this and how to solve this problem?

Thanks.

---

<div class="post-metadata">

**Author:** ![kgoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kgoh](https://www.ruby-forum.com/u/kgoh)\
**Post date:** [April 12, 2008, 1:11am UTC](https://www.ruby-forum.com/t/need-help-in-option-parser/134561/2 "2008-04-12T01:11:00Z")

</div>

Kwong Goh wrote:

> I am using optionparser to take in arguement. However, it seems like the  
> option parser does not accept “&” “|” “\<” “\>” as the arguement when they  
> are entered from the command line.
> 
> For example, I use opts.on(“-d option”), when I enter -d 1&2 in the  
> command line, it will only accept 1 in this case.
> 
> May I know what is the reason for this and how to solve this problem?
> 
> Thanks.

Depends on what O/S and shell you’re using. In most Linux shells those  
characters are interpreted by the shell. In Windows both \< and \> are  
interpreted by [cmd.com](http://cmd.com). I don’t know about the others.

You can make the shell ignore those characters by surrounding them with  
quotes or escaping them with an acceptable escape character such as a  
backslash.

---

<div class="post-metadata">

**Author:** ![kgoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kgoh](https://www.ruby-forum.com/u/kgoh)\
**Post date:** [April 12, 2008, 1:13am UTC](https://www.ruby-forum.com/t/need-help-in-option-parser/134561/3 "2008-04-12T01:13:55Z")

</div>

Try putting 1&2 in quotes “1&2”. & | \< \> are used by the terminal.

Becker

---

<div class="post-metadata">

**Author:** ![kgoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a3d4f5/32.png) [@kgoh](https://www.ruby-forum.com/u/kgoh)\
**Post date:** [April 12, 2008, 1:15am UTC](https://www.ruby-forum.com/t/need-help-in-option-parser/134561/4 "2008-04-12T01:15:40Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Kwong Goh wrote:  
| I am using optionparser to take in arguement. However, it seems like the  
| option parser does not accept “&” “|” “\<” “\>” as the arguement when they  
| are entered from the command line.  
|  
| For example, I use opts.on(“-d option”), when I enter -d 1&2 in the  
| command line, it will only accept 1 in this case.  
|  
| May I know what is the reason for this and how to solve this problem?

Try to use a ‘dir \> text.txt’, or ‘ls \> text.txt’, or ‘dmesg | grep a’  
on the command line.

The symbols OptionPArse doesn’t accept are reserved by the OS.

(| is the pipe in \*NIX, && allows comamnd chaining in Windows and \*NIX,  
\< and \> are redirectors, which allow the use of a file as input to a  
command, or direct the output of a command to a file, respectively.

There is no way _I_ am aware of to circumvent these, except “Stop using  
them”. Maybe others know more.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

Make sure all variables are initialised before use.  
~ - The Elements of Programming Style (Kernighan & Plaugher)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf/8JIACgkQbtAgaoJTgL9SbwCfZ0ZrK+fn5MdWAxtI9fxD1KdT  
XTwAn3CfOlvi72aEwq8LUJEeSeEz2L0S  
=fPwe  
-----END PGP SIGNATURE-----
