Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED] Limit on args passed to a script

Featured Replies

There appears to be a limit of 9 on the amount of arguments that may be passed to an external script from a plugin.  Can Tom or someone else in the know confirm this as by design or as a bug. Example code below

 

Thanks

 

snip from test.php

        <form name="test_settings" method="POST" action="/update.htm" target="progressFrame">
                <input type="hidden" name="cmd" value="/etc/rc.d/rc.test">
                <input type="hidden" name="arg1" value="test">
                <input type="hidden" name="arg2" value="this">
                <input type="hidden" name="arg3" value="is">
                <input type="hidden" name="arg4" value="just">
                <input type="hidden" name="arg5" value="a">
                <input type="hidden" name="arg6" value="test">
                <input type="hidden" name="arg7" value="theres">
                <input type="hidden" name="arg8" value="nothing">
                <input type="hidden" name="arg9" value="of">
                <input type="hidden" name="arg10" value="real">
                <input type="hidden" name="arg11" value="importance">

                <input type="submit" name="runCmd" value="Apply" style="margin-bottom:35px">
                <button type="button" style="margin-bottom:35px" onClick="done();">Done</button>
        </form>

 

from rc.test

#!/bin/sh

test_config() {
  echo "# test configuration" > /boot/config/plugins/test/test.cfg
  echo "ARG1=\"$ARG1\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG2=\"$ARG2\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG3=\"$ARG3\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG4=\"$ARG4\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG5=\"$ARG5\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG6=\"$ARG6\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG7=\"$ARG7\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG8=\"$ARG8\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG9=\"$ARG9\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG10=\"$ARG10\"" >> /boot/config/plugins/test/test.cfg
  echo "ARG11=\"$ARG11\"" >> /boot/config/plugins/test/test.cfg
}

case "$1" in
        'test')
                ARG1=$1
                ARG2=$2
                ARG3=$3
                ARG4=$4
                ARG5=$5
                ARG6=$6
                ARG7=$7
                ARG8=$8
                ARG9=$9
                ARG10=$10
                ARG11=$11
                test_config
        ;;
        *)
                echo "usage $0"
esac

 

config written (note arg10 and 11 contain the value of arg1 with a 0 or a 1 at the end)

# test configuration
ARG1="test"
ARG2="this"
ARG3="is"
ARG4="just"
ARG5="a"
ARG6="test"
ARG7="theres"
ARG8="nothing"
ARG9="of"
ARG10="test0"
ARG11="test1"

I don't know these script languages but:

 

If $arg1 is a variable and "test" is it's content than it's clear to me that $arg10 gives "test0" and $arg11 gives "test1" if the first match for a variable is taken in that script language.

 

$arg1 --> test
$arg10 --> test"0"
$arg11 --> test"1"

 

It's no limit on args - the problem is the names you are using.

 

  • Author

@hawihoney

 

Thanks for pointing me towards the right direction although it was not really with my variable names . 

The issue that I was having is actually nothing to do with unraid, but with the way bash handles arguments.

 

If less than 10 arguments are passed to a bash script they may be accessed with $1 - $9.  However more that that requires something more like the following

 

for TEST in "$@"
  do
       echo $TEST
  done

 

or

 

while (("$#")); do
   echo $1
   shift
done

 

 

there is a limit.

 

It's not a limit to unraid, but it's more of a limit to Linux Shell script.

 

Unix/Linux shell is only able to handle 9 parameters at a time.

 

With that form, what you're basically doing is running a script in the command line through html. (that's why its name is runCMD).

so when the form is submitted, it's basically running something like this:

 

/etc/rc.d/test arg1 arg2 arg3 ...

 

In your code you have this line:

 

                
ARG10=$10
ARG11=$11

 

There is no $10, $11 parameter. THis is getting accepted as $1 + "0", $1 + "1".

 

so hawihoney was partially right i guess lol

 

anyway, apparently thedroid beat me to it lol but in order to use more than 9 parameters, you need to use "shift" command.

I did something else in some of my plugins.

 

I wrote a PHP that writes all parameters to temporary file and in the PHP I run the rc.test which in turn reads the paramaters - this way there is no limit to amount of args passed.

 

I tried to use the "shift" command but didn't get it to work successfully.

 

There is a limit for bash, but its quite high.  Pass the args as you currently do from php/web form and in the back end bash script, address args > 9 as this...    ${10} ${11} etc.

 

Check my denyhosts plugin for a working example.

 

 

Regards,

overbyrn

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.