how do you define a variable to an integer at the command line. For example if i want to assign A=22 and B=23 and then have the A and B = a separate variable such as C..? I am confused on the syntax of this at the command line. I understand how to set variables in a script but how would i do it from a command line using only 1 line?
A=22; B=23; ((C=A+B)); echo $A $B $C
Assuming Bash or Korn shell.
set A=22
set B=23
set A=%C%
set B=%C%
In windows bat-files. Also be careful not to use any extra spaces in batch file syntax. It can screw up everything.
Related
I have a TCL script that is run by Libero using a file path provided as an argument to open a project. The file path is C:\Users\me\Documents\FPGA projects\file.prjx
I am running the script according to Libero TCL Reference Guide (pages 51 - 52) to run the script on the command line. On page 47, the doc outlines how to work with filenames with spaces; using braces or in the case where it is used as an argument use double quotes.
The command I am trying to execute is:
Path\to\libero SCRIPT:export.tcl SCRIPT_ARGS:""C:\Users\me\Documents\FPGA projects\file.prjx""
The outer set of double quotes is to follow the syntax outlined in page 52 of the document for providing arguments and the inner set of double quotes is to handle the white space in the first argument. I had expected $argv 0 to be C:\Users\me\Documents\FPGA projects\file.prjx, but instead $argv 0 is actually C:\Users\me\Documents\FPGA.
I added a print statement to the script to print $argv:
puts $argv
This gives a result of C:\Users\me\Documents\FPGA so the rest of the file path is not being interpreted as even being a second argument.
My assumption is that the conventions outlined in the document are just standard TCL conventions for providing a file path containing forward slashes and spaces as an argument. I have not been able to find an example of passing a similarly formatted argument in TCL. Any ideas?
I'm not sure it's the same issue but, having MagicSplat tclsh.exe and wish.exe linked to *.tcl and *.tk files in Windows (7 to 11), calling scripts this way:
processDIR.tcl "c:\My directory\subdir"
evals arguments only till first space, becoming "c:\My" BUT calling scripts like this:
tclsh.exe processDIR.tcl "c:\My directory\subdir"
trespasses complete argument.
Could you give it a try?
I'm trying to execute a .VB script along with some other arguments.
I'm calling system("$cmd"), where
my $cmd = "Report.exe $app_env $rpt_Dir $eff_date";
and
my $rpt_Dir = "\\\\server\\folder\\Target Report\\test";
The problem I am having is that (I think) the space between "Target Report" is making the script treating it as 2 arguments.
And the reason why I didn't just surround the path with "" and pass it as an argument instead of saving it to a variable is that the path changes based on the date.
And it's not a first choice that I change the code in the .VB script.
On Windows, the system call uses cmd.exe to process commands, so you need double quotes around any parameters that contain spaces
Set your $cmd up like this
my $cmd = qq{Report.exe $app_env "$rpt_Dir" $eff_date};
The qq{...} construction is identical to ordinary double quotes, but it allows you to choose your own delimiters so that you don't have to escape any embedded double quotes
Then you can write
system($cmd);
It is wrong to put quotes around a solitary scalar variable
You can pass an array of args to system. If you do this, you won't be tripped over by quote interpolation.
system ( "Report.exe", $app_env, $rpt_Dir, $eff_date );
You can simply enclose the $rpt_Dir variable in single quotes:
my $cmd = "Report.exe $app_env '$rpt_Dir' $eff_date";
and it will be treated as a single arguement
I've been searching all over the place and since I'm taking my first steps in PERL this might be one of he dumbest questions but here it goes.
So I'm creating a script to manage my windows and later bind it to keyboard shortcuts, so I I'm trying to run a command and passing some variables:
my $command = `wmctrl -r :ACTIVE: -e 0,0,0,$monitors->{1}->{'width'}/2,$monitors->{1}->{'height'}`;
But I get an error saying I'm not passing the right parameters to the command, but if I do this, everything works great:
my $test = $monitors->{1}->{'width'}/2;
my $command = `wmctrl -r :ACTIVE: -e 0,0,0,$test,$monitors->{1}->{'height'}`;
So do I really have to do this? assign it first to a variable and then pass it, or there's a more elegant way of doing it?
The backticks operator (or the qx{}) accepts A string which is (possibly) interpolated. So accepts string and not expression like $var/2.
Thats mean than the $variables ($var->{1}->{some} too) are expanded but not the arithmetic expressions.
Therefore your 2 step variant works, but not the first.
If you want evaluate an expression inside the string you can use the next:
my $ans=42;
print "The #{[ $ans/2 ]} is only the half of answer\n";
prints
The 21 is only the half of answer
but it is not very readable, so better and elegant is what you're already doing - calculate the command argument in andvace, and to the qx{} or backticks only pass the calculated $variables.
Quick question... I'm trying the following:
set changedir "cd $JSDIR/"
eval $changedir
..Where $JSDIR is defined already. Running this script gives the error: "set: Variable name must begin with a letter."
What's the fix?
Thanks.
That's not an error message generated by Tcl, because Tcl's variables most definitely do not need to begin with a letter. OK, it tends to be convenient to keep them alphanumeric because the $var shorthand syntax is more restrictive than the general space of variable names, but the set var form can handle virtually anything.
I'm guessing that script is being evaluated by something that isn't Tcl, perhaps bash?
Try to set changedir cd ${JSDIR/} instead
This message can appear when in fact the variable name is entirely correct, and the real problem is that the variable value needs to be quoted. Try instead of: set changedir "cd $JSDIR//"
I'm writing some PowerShell scripts to work with our source control software (which is not a PowerShell cmdlet) and I'm running into a problem using variables as command line arguments when they are preceded by an =, like this:
cm mklabel lb:BL$baseline -c=$comment
This ends up create a label in with the comment of "$comment". If I put a space after the =, it looks like it evaluates the variable properly, but the command does not associate the comment with -c argument anymore. Is there a way to force the variable to be evaluated despite the =?
Try:
cm mklabel lb:BL$baseline -c=($comment)
Try
cm mklabel lb:BL$baseline "-c=$comment"