# RunScript Single line script with Arg

**URL:** <https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 25, 2023, 1:47pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864 "2023-07-25T13:47:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [July 25, 2023, 1:47pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/1 "2023-07-25T13:47:42Z")

</div>

trying to use expression runScript command to run a single l

`runScript("args[0].split('/')[-1]",0, {[.]Port Number})`

where [.]Port Number = "GigabitEthernet1/0/1"  
looking for evaluate to "1"  
but doesn't work like this. I suspect it is how I am calling args[0] but not sure how to fix.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [July 25, 2023, 1:49pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/2 "2023-07-25T13:49:14Z")

</div>

Looks like this works but not sure if that is optimal?

`runScript("'"+{[.]Port Number}+"'.split('/')[-1]")`

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [July 25, 2023, 2:07pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/3 "2023-07-25T14:07:58Z")

</div>

~~In runscript something like this would work.~~ This is inconvenient when passing arguments.

```auto
runScript("str.split('some string/some other string','/')",0)

```

There's also [split in the expression language](https://docs.inductiveautomation.com/display/DOC81/split), which I imagine would be easier and more performant.

```auto
split("somestring/some other string","/")[1,0]// --> some other string

```

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [July 25, 2023, 2:14pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/4 "2023-07-25T14:14:04Z")

</div>

Perhaps this as another option?

```auto
substring({[.]Port Number}, 
  lastIndexOf({[.]Port Number}, "/")+1, 
  len({[.]Port Number})
)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 25, 2023, 2:19pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/5 "2023-07-25T14:19:03Z")

</div>

It is terrible to modify the string that `runScript` uses. What you are trying to do with the first expression is precisely what my [objectScript()](https://www.automation-pros.com/simaids/doc/expression.objectscript.html) expression function supports, including using `args` in that fashion. (But omitting the polling interval.)

When IA added the ability to pass args to `runScript()` in [v7.8.0](https://inductiveautomation.com/downloads/releasenotes/7.8.0) (note the comment in that changelog), they chose to **not** support one-liners with an `args` tuples, but instead require the string to **name** a function or method that would implicitly receive the `args` tuple.

Your choices are:

- Move the split operation into a function in your gateway scripting project's script library and call with `runScript()`'s arg-passing syntax, or

- Continue using the very non-optimal string contortions, or

- Install my Simulation Aids module and use `objectScript()`.

- Use Kevin's expression, but be aware that if `{[.]Port Number}` changes while the expression is executing, you can get a broken result.

---

<div class="post-metadata">

**Author:** ![rfolkes](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rfolkes](https://forum.inductiveautomation.com/u/rfolkes)\
**Post date:** [July 25, 2023, 2:32pm UTC](https://forum.inductiveautomation.com/t/runscript-single-line-script-with-arg/76864/6 "2023-07-25T14:32:23Z")

</div>

thanks, Using Kevins solution. In this case I am not concerned with changing value since it should be set when first instanced and shouldn't change after that.
