.sh executeCommandLine pass parameter

Hi there,

I am struggling to pass a parameter via executeCommandLine to an .sh script.
This way I am calling my .sh scripts:

    val result = executeCommandLine(Duration.ofSeconds(10), path)

Where do I have to put my parameters and how do I call them within the .sh script?
I tried things like:

    val result = executeCommandLine(Duration.ofSeconds(10), path, parameter)

or

    val result = executeCommandLine(Duration.ofSeconds(10), "path/script.sh parameter")


But am not able to call the parameter via $1 within the script. Any help greatly appreciated!

Then something else seems not to be ok.

These are my entries in a rule file:
executeCommandLine( Duration.ofSeconds(5), β€œ/etc/openhab/scripts/light.sh”, β€œOUT4”, β€œ1” )
executeCommandLine( Duration.ofSeconds(5), β€œ/etc/openhab/scripts/light.sh”, β€œOUT4”, β€œ0” )

This is content of the above script:

#!/bin/bash

switch=$1
OnOff=$2

If that does not work for you:

  • check if the script is executable and readable
  • add e.g. echo abc > /tmp/debug.txt to your script to check if it is executed
  • add e.g. $OnOff >> /tmp/debug.txt to your script ( adapted to your variable name ) to check if content is passed to the script

I think the way I use the parameter within my script is probably not the right way to do so:

This way the script works (without parameter):

curl -X 'PUT' \
  'http://192.168.1.210:7190/api/Config/UpdateCarConfiguration?carId=1' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "chargeMode": 0
}'

Now, trying to replace β€œ0” with $1:

curl -X 'PUT' \
  'http://192.168.1.210:7190/api/Config/UpdateCarConfiguration?carId=1' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "chargeMode": $1
}'

not working :frowning:

okay: just found my mistake by typing it.

This way it works:

curl -X 'PUT' \
  'http://192.168.1.210:7190/api/Config/UpdateCarConfiguration?carId=1' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "chargeMode": '$1'
}'

1 Like

right.

It does not work because of the single quotes around $1. $1 then is not replace with it’s content but used literally.
Replace ’ with " and use " instead of " inside -d.

indeed that is an other way to solve it.