0

I have a bash script wherein I have to provide parameters. But I don't know how many parameters to be supplied while executing the script.

I don't have permission to view/edit the script to know how many parameters the script is accepting.

Please let me know if there is any way to know how many parameters a script can accept without view/edit the script.

Inian
  • 80,270
  • 14
  • 142
  • 161
  • Possible duplicate of [checking number of arguments bash script](http://stackoverflow.com/questions/18568706/checking-number-of-arguments-bash-script) – Inian Jun 10 '16 at 08:07
  • Just execute the script without any parameter. If the owner of script had carefully written the script then, the script would print the expected number of arguments it expects and possibly description of same. – sameerkn Jun 10 '16 at 08:10
  • If you can not view it ( no read permission) you are pretty much out of luck; as you can not execute it either – ring bearer Jun 10 '16 at 08:11
  • Try running `theScript --help` or `theScript -h` – Mark Setchell Feb 02 '17 at 10:54

1 Answers1

0

Perhaps you can try supplying a variable number of arguments and seeing which one will work. To generate a script that creates variable args you could hack up a script like this:

#!/bin/bash
# will send upto 5 command line arguments
for i in `seq 5`
do
    # replace newlines with spaces
    j=`seq $i | tr '\n' ' '`
    echo foo $j
done

It will result in something like:

foo 1
foo 1 2 
foo 1 2 3 
foo 1 2 3 4 
foo 1 2 3 4 5 

where 'foo' is the name of the program you need to run. Note that method this may only work if the script does not require any command line switches.

trohit
  • 319
  • 3
  • 6