2

I am currently shell scripting and I would like to know how to make a - option while making a function. When you would execute a command similar to the following:

test -f

Here is the function I am using:

function test()
{
      echo $1;
      echo $2;
}

How could I add a -t for echo twice option?

Input:

 test -t Hello

Output:

  Hello
  Hello

I am using iTerm and oh-my-zsh.

Thanks, base2101

Base2101
  • 33
  • 7
  • Look up how to use [`getopts`](http://stackoverflow.com/questions/402377/). – Jonathan Leffler Jan 23 '16 at 01:01
  • I didn't know the keyword getops. You can close it if you want. – Base2101 Jan 23 '16 at 01:08
  • Technically, [`getopts`](https://www.gnu.org/software/bash/manual/bash.html#index-getopts) is a (built-in) command rather than a keyword. This link is to the Bash manual rather than an SO question, though. – Jonathan Leffler Jan 23 '16 at 01:11
  • Please don't name your function `test` -- that's the name of a rather important standard command, and if you override it you may break some scripts etc in very strange ways. – Gordon Davisson Jan 23 '16 at 06:00

0 Answers0