I want to execute a powershell script from sqlplus which use a the variable a.
As you can see if you execute this code, a isn't recognized. I would like this code to print 22, not a or :a
variable a varchar2;
a='22'
host powershell.exe echo :a
host powershell.exe echo a
:a
a
You could use a substitution variable:
define a=22
host powershell.exe echo &a
If you already have the bind variable defined and populated by a process you don't want to change, you can set the substitution variable value using a dummy query and column ... new_value syntax.
Related
From a bat file I am using a process which is calling SQL/Plus in the same way:
#echo off
start sqlplus user/password#instance_name file.sql <instance_name>
echo End of process
pause
Inside file.sql I have something like :
SET FEEDBACK OFF
SET UNDERLINE OFF
SET PAGESIZE 0
SET VERIFY OFF
SET SCAN ON
SET HEADING OFF
SET RECSEP OFF
SET TRIMSPOOL ON
SET FEEDBACK OFF
SET TERMOUT OFF
SET LINESIZE 1000
SET BLOCKTERMINATOR OFF
set instance_name=<FROM PARAMETER>
SET VERIFY ON
SET HEADING ON
EXIT
How can I get the name which I am passing as parameter in SQL/Plus?
Use &1
From the documentation the SQL/Plus command has the syntax:
SQLPLUS [ [Options] [Logon|/NOLOG] [Start] ]
Then the START parameter:
Start
#{url|file_name[.ext]} [arg ...]
Specifies the name of a script and arguments to run. The script can be called from the local file system or from a web server.
SQLPlus passes the arguments to the script as if executing the file using the SQLPlus START command. If no file suffix (file extension) is specified, the suffix defined by the SET SUFFIX command is used. The default suffix is .sql.
See the START command for more information.
Then for the START command:
arg ...
Data items you wish to pass to parameters in the script. If you enter one or more arguments, SQL*Plus substitutes the values into the parameters (&1, &2, and so forth) in the script. The first argument replaces each occurrence of &1, the second replaces each occurrence of &2, and so on.
So my goal is to take a variable that is in my TCL file and pass it to my shell script for it to be able to use. Right now I am able to echo to get the result of my variable but I cannot for some reason set that result to a variable in my bash script.
Here is an example of my TCL script:
set file_status "C"
Here is what I have for my bash script:
echo 'source example.tcl; foreach _v {file_status } {puts "\"[set $_v]\""}' | tclsh
file_status='source example.tcl; foreach _v {file_status } {puts "\"[set $_v]\""}' | tclsh
echo $file_status
So the first echo statement above works but after I set the file_status variable for some reason the second echo statement doesn't work.
Doing it in general requires very complex code; Tcl variables are capable of holding arbitrary data (including full binary data) and don't have length restrictions, whereas Shell is a lot more restricted. But it's possible to do something for the common cases where the values are plain text without NULs. (C would be an excellent example of such a value.)
When passing to a subprocess, by far the easiest way is to use an environment variable:
set the_status "C"
set env(file_status) $the_status
exec bash -c {echo "file status is $file_status"} >#stdout
That has length restrictions, but it's extremely easy.
If you're sending the variable to some other process, your best bet is to write a little script (here, I'm sending it to stdout):
puts [format {file_status='%s'} [string map {"'" "'\''"} $the_status]]
That is producing a script that just sets the variable. (string map is turning single quotes into something that works inside single quotes; everything else doesn't need conversion like that.) You run the script in the shell with eval or source/. (depending on whether it is in a string or in a file).
Very large data should be moved around inside a file or via a pipe. It needs much more thought in general.
I would output shell syntax from Tcl and source it into your running shell:
Given
$ echo 'source example.tcl; foreach var {file_status} {puts "$var=\"[set $var]\""}' | tclsh
file_status="C"
then
source <(echo 'source example.tcl; foreach var {file_status} {puts "$var=\"[set $var]\""}' | tclsh)
declare -p file_status
outputs
declare -- file_status="C"
Using /bin/sh, you could:
var_file=$(mktemp)
echo ... | tclsh > "$var_file"
source "$var_file"
rm "$var_file"
Following is a screenshot of how I am setting an environment variable in Jenkins.
I am trying to access it in a shell script, but it is not echoing its value.
echo "Starting ..."
echo ${BUILD_NUMBER}
echo ${DATABASE}
${BUILD_NUMBER} is a global env variable.
The correct use of variables in Jenkins is the following:
echo "The current build number is: ${BUILD_NUMBER}"
The important part is to use ". If you would use ' Jenkins would not notice that you want to access the variable and simply print your variable as string.
Source: Jenkins String Interpolation
I have a problem with an execution of a shell script into a remote shell.
I can't get value of $ARQ_END.
ssh -T user#MACHINE << 'EOSSH'
/app/work/leo/ReturnFileName.sh #This script returns a filename like: ADDRESS_BR_RECIFE_20170913.txt
ARQ_END="`/app/work/leo/ReturnFileName.sh`"
EOSSH
echo $ARQ_END #Returns nothing! Expected to return: ADDRESS_BR_RECIFE_20170913.txt
Setting a variable in a subshell isn't visible in the parent shell. You need to set the variable directly in the parent shell. The way to do that is to pass the output of ReturnFileName.sh up through the ssh session and to the parent shell and capture it there.
ARQ_END=$(ssh user#MACHINE /app/work/leo/ReturnFileName.sh)
echo "$ARQ_END"
Thanks, it works!
I used the case as you posted:
ARQ_END=$(ssh user#MACHINE /app/work/leo/ReturnFileName.sh)
echo "$ARQ_END"
How do i do the equivalent of this bash style command invocation in powershell 1.0
output = `VAR1=value /path/someCommand`
In essence i need to manufacture a private & temporary $env:VAR1 for the purpose of invoking someCommand.
You can set a process environment variable in PowerShell like so:
$env:VAR1 = 'value'
Then invoke the command:
/path/someCommand
Then remove the process env var:
remove-item Env:\Var1
Assuming you want to store the output of that command in var1:
$var1 = $_ | /path/someCommand
Assuming you want an alias so output will run that code whenever called:
Set-Alias output "$var = /path/someCommand"