Converting Bash shell scripts to batch files - shell

I am trying to convert a shell script to a batch file line by line and command by command. However, I cannot seem to get around the following line. Any help appreciated.
OPTS="%OPTS -Dlog4j.configuration=file:.\log4j.properties"

I don't know linux shell but I think the equivalent is this:
Set "OPTS=-Dlog4j.configuration=.\log4j.properties"
Then you can load the stored ...Options¿? like an argument:
Start Application.exe %OPTS%
".\" means the current directory of your script, ensure if "file:.\" means the same in linux OS.

Related

How to write/store output of commands in a variable in Windows Command Line?

I want to set a directory path to variable using Windows Command Line without any user-interaction. So, like we do in Ubuntu OS:
my_path=$(pwd)
Here, output of pwd will get stored in my_path.
How to do this kind of task in Windows Command Line?
Actually, the more natural way in bash would have been
my_path=$PWD
Taking over this idea to Windows batch language, it would become
SET my_path=%CD%
The main difference is, that in Windows, my_path would end up in the environment automatically, while in bash, you would have to do this manually.

Instead of giving command for batch mode, give .scm file path?

It is possible to supply batch commands directly with the -b flag, but if the commands become very long, this is no longer an option. Is there a way to give the path to an .scm script that was written to a file, without having to move the file into the scripts directory?
No as far as I know. What you give in the -b flag is a Scheme statement, which implies your function has already been loaded by the script executor process. You can of course add more directories that are searched for scripts using Edit>Preferences>Folders>Scripts.
If you write your script in Python the problem is a bit different since you can alter the Python path before loading the script code but the command line remains a bit long.

Cross-platform command line script (e.g. .bat and .sh)

I noticed that Windows 7 enables to execute .sh files as if they were .bat files. That got me wondering whether it is possible to write a .sh file such that it can be executed in Windows and Linux (let's say bash).
The first thing that comes to my mind is to fabricate an if-statement such that Windows and Ubuntu can deal with it and jump into the according block to execute plattform-specific commands. How could this be done?
Note: I know this is not good practice. I also know that scripting languages like Python are far better suited to solve this problem than a mixed-syntax command line script would be. I'm just curious...
You could use this:
rem(){ :;};rem '
#goto b
';echo sh;exit
:b
#echo batch
It's valid shell script and batch, and will execute different blocks depending on how it's run.
Modify the echo and #echo lines to do what you want.
AFAIK, you can't directly run .sh files from Windows' cmd.exe. For that you'll need a *nix emulation layer to run the shell. Check out Cygwin or Msys/MinGW

How to run a tcl script in windows machine using "./script.tcl" format?

TCL script :
#!c:\Tcl\bin\tclsh
set a 1
while { $a < 11} {
puts $a
incr a
}
Its working fine If I run this script as "tclsh script.tcl". But I want to run this script in Windows machine as "./script.tcl". Its throws following error:
C:\Users\Balu\Desktop>./script.tcl
'.' is not recognized as an internal or external command, operable program or batch file.
NOTE : This script is working fine in Unix machine, If I run as "./script.tcl".
Please suggest me any ideas to achieve this.
Thanks in advance.
Windows doesn't understand the #! first line syntax at all. That's completely Unix-specific.
To run your script, do something like:
C:\Users\Balu\Desktop> tclsh .\script.tcl
If you have an association set up for Tcl script files with tclsh in Explorer, you could also run them by appending ;.TCL to the PATHEXT environment variable.
If you are using linux then only ./script.tcl way will work.
In Windows for running the tcl script you need to run like this tclsh script.tcl. Assuming tcl installer has already set the PATH environment variable of System or User Profile. And the script.tcl is in the current working directory.
In your case (.) means current working directory.

execute user inputed Windows (or bash) commands from batch (or bash) file?

Ok, so I have this batch script and what I want to happen is that when you run the script it does some standard stuff like change the path and access files etc... but after it's done that it goes back to being a normal cmd prompt/terminal where I can type in commands at free will.
Can this be done (in either dos or bash)? Is there like an execute command that I can put in an internal while loop or is there a command where when the scirpt ends it can go back to the normal cmd/terminal?
Do you need a full bash prompt?
Or would something like this be enough?
#!/bin/bash
echo -n "Enter cmd: "
read COMMAND
echo ${COMMAND} | bash
Also, in a script, you can just execute bash and get a full prompt in the current environment.
In Dos / windows command prompt if you run the batch file from command line you will get the prompt back always by default. Just like running any other command in command prompt.
Also in windows when the batch file execution is complete you can just put Cmd.exe when everything has finished running I.e at the end of the batch file.
Hope this helps!
E.g
#echo off
Echo running
.
.
.
Cmd.exe
Or even at the end
Echo %command% | Cmd.exe
Never mind, I got a good solution using this code: (for windows)
set /p command=CMD:
%command%

Resources