Pass Data In Variable From Eggplant to Bash Script

I’m trying to pass data held in a list in the Sensetalk programming language to a bash script. How do I do that?

If you have an existing bash, I would recommend using a shell command:

If you are trying to use Eggplant to generate the bash script, you can put the commands directly into a file using file functions (e.g. put myBashCommands into file “/tmp/bashscript.sh”).

1 Like

Thank you for the references and ideas.

Thanks Dave, that covers both use cases very nicely. I’m not sure though that those approaches would work when invoking a “headless” sensetalk script in a build pipeline (in a bash script) that needs to pass command line variables into the instance of the process? I suppose that could be done by writing them to a file that the SenseTalk script opens in the working directory, but that is a bit clumsy when there may be multiple instances of scripts running concurrently - passing linux/using argument vector (argc, **argv in C language) arguments would be highly desirable. So that, for example, we have a Git repository that users check into, and when they do a build pipeline runs that compiles their project, runs Eggplant scripts on it using the command line client, and then flags up any test results that are not nominal for inspection…

I suppose that could be done by writing them to a file that the SenseTalk script opens in the working directory, but that is a bit clumsy when there may be multiple instances of scripts running concurrently

The above is what I was trying to avoid. There is not really a clean way of doing this. So, we hard coded the variables into the bash scripts. Not the most ideal solution, but it works.

Could you share a snippet? I’m intrigued, I would have thought that you didn’t need to hard code them in the bash script. I’m a linux bash programmer fwiw Stephen :smiley: - the critical programming API call would seem to be getenv(3) in the linux manual, or execve (2), which ST would need to have a wrapping call for. It presumably does for execve because it can fork and execute a child process.

I won’t be able to post a snippet. I’m not extremely familiar with bash syntax, but I basically just need to pass a list from a Sensetalk script to a bash script. That list needs to be saved in a variable in the bash script. Then, in the bash script I need to iterate through the list and perform commands through the command line on each element in the list.

Thanks - I have a better understanding of what the Use Case is now; I can do some more investigation, because we may need this pattern also.

Thanks! I would greatly appreciate any assistance on this, because right now, we are just hard coding the list in the bash script and then calling the bash script.

Not an ideal way of doing things, because our list changes every time. We read in a different data set every test and that new data set becomes the new list.

So we would really like to just read in the new list and send that list to the bash script. The only time the bash script is called is when we have a catastrophic system issue and need to bail out and kill all processes. Each element in the list is a process we are going to kill if needed. So, hard coding all the processes that are possible to kill in the bash script and then calling the bash script when there is a system failure isn’t too bad.

However, if we could only kill the processes currently running vs. killing all possible processes one by one, even if they are not running would speed things up.

So, we would rather pass the list of all running processes to the bash script and use that dynamic changing list every time in the bash script vs. iterating through processes to kill that are not running.

You might try something along these lines. In SenseTalk you could do:

put the listFormat into previousListFormat
set the listFormat to {prefix:empty, suffix:empty, separator:space, quotes:quote}
set shellCommand to commandName && listOfProcesses
set the listFormat to previousListFormat
shell shellCommand

That will call your commandName script and pass all of the items in your listOfProcesses on the same line with quotes around each. Then I think you can use something like $* in your bash script to get the list of values that were passed in.