Sbt external process can't process `eval` command - bash

Running in sbt command "eval $(minikube docker-env)" !! log give exception.
[error] java.io.IOException: Cannot run program "eval": error=2, No such file or directory
but same command in bash script
#!/usr/bin/env bash
eval $(minikube docker-env)
Runn as "eval.sh" !! log
Work fine.
I can't understand why. Please explain.

eval is a shell feature. There is no way to call it from java to set up the environment for future commands the way you can for a shell.
If you want to run a second command from Java that depends on doing eval "$(minikube docker-env)" first, you can instead run a single shell with both commands:
String shellCommand = "eval \"$(minikube docker-env)\"; your-second-command";
Runtime.exec(new String[] { "sh", "-c", shellCommand });

Related

Is it possible to run commandLine in gradle with bash -c?

I have a task in a build.gradle file, in which I'd like to run this command:
(export ENV_VAR=/my/path ; /path/to/build.sh)
I tried running this in gradle:
task myTask {
doLast {
exec {
commandLine ['bash', '-c', '"(export ENV_VAR=/my/path ; /path/to/build.sh)"']
}
}
}
Unfortunately, I have an error that says
Successfully started process 'command 'bash''
bash: (export ENV_VAR=/my/path ; /path/to/build.sh): No such file or directory
Now I'm sure the file exists and the specified paths are correct. Running this command manually in the terminal works.
Is there something in gradle that makes a bash -c like this not work? I can't think of another way to make an export like this otherwise.
Try without the extra quotes:
commandLine ['bash', '-c', '(export ENV_VAR=/my/path ; /path/to/build.sh)']
When you run that in the command line, your shell needs the quotes to pass to the command (which happens to be bash) as a single argument, but gradle is already doing that with that syntax, so bash is receiving literally one argument "(export ENV_VAR=/my/path ; /path/to/build.sh)" and since it does not recognize this as internal syntax, tries to run a command with this name.

How to debug a tcsh script and put the debugged output in a file?

I want to debug my tcsh script. Like in sh script if we add set command with -x then it prints the execution of script.
#! /bin/sh
set -x
exec 2>/usr/bin/error.log
#My script code
And I tried this as explained here . But still don't know how to print in a file? I am writing below code:
#! /bin/tcsh
set echo
exex 2>/usr/bin/error.log
I am getting permission denied error.I have also tried running as root still same error. But that can be the error in my script. So I want to check in error.log where does the error occur. But after I run script the error.log file is not getting generated. Is there any other way to write stderror for tcsh? Can we use exec command in tcsh?
Also are tcsh and csh both same things or different?

Jenkins fails with Execute shell script

I have my bash script in ${JENKINS_HOME}/scripts/convertSubt.sh
My job has build step Execute shell:
However after I run job it fails:
The error message (i.e. the 0: part) suggests, that there is an error while executing the script.
You could run the script with
sh -x convertSubt.sh
For the safe side, you could also do a
ls -l convertSubt.sh
file convertSubt.sh
before you run it.
make sure that the script exist with ls
no need to sh , just ./convertSubs.sh ( make sure you have run permissions)

Jenkins Pipeline cannot execute SH command file in a Windows slave

I'm executing this code:
node('my_windows_slave') {
sh 'ls'
}
In my Windows slave I can properly execute sh command:
But the pipeline script can't run the .sh file:
[Pipeline] sh
[D:\workspace\sandbox_pipeline] Running shell script
sh: D:\workspace\sandbox_pipeline#tmp\durable-2d7dd2f8\script.sh: command not found
What I could notice is that this .sh file is not even created, once I tried with bat and worked fined.
Any clue what could be the problem?
[UPDATE]
Jenkins somehow can't create the SH temporary file. Already checked the log, permissions, everything that came to my mind.
I will leave my workaround as an answer for while before approve it once I'm still not 100% sure about the root cause and might someone else show up with a elegant solution...
def shell(command) {
return bat(returnStdout: true, script: "sh -x -c \"${command}\"").trim()
}
Attention
You still executing SH commands in a CMD, it means some %d for example can break your SH command.
Use the bat step instead of sh.
From Jenkins docs:
Windows-based systems should use the bat step for executing batch commands.

Execute command in variable bash script

I have this .sh script:
#!/bin/bash
CLASSPATH=$1
PACKAGE=$2
INPUT_FILE=$3
javac -classpath $CLASSPATH classes/$PACKAGE/$INPUT_FILE.java
cp classes/$PACKAGE/$INPUT_FILE.class ../WEB-INF/classes/$PACKAGE/
eval "$CATALINA"
And $CATALINA is set on .bashrc:
CATALINA_PATH="/var/local/tomcat/bin/catalina.sh"
CATALINA="sh $CATALINA_PATH stop && sh $CATALINA_PATH run"
But when I execute my .sh script it doesn't execute the command inside $CATALINA.
Am I doing something wrong?
Thanks!
Since I'm running a shell script, it uses a sub-shell so it cannot access the parent shell's environment.
Problem solved running the shell script in this way:
. ./script.sh

Resources