The default Unix shell does not give you a one to one equivalent for all the features you're using. Here are what you can do with the basic shell:
Trace
@echo off
By default a shell script is silent, so it is "off" by default. The flag to turn on trace is -x
(set -x
).
Loop 1 to 10
for /L %%n in (1,1,10)
This can be done in a Unix shell script using a variable and a while
. Newer shells, such as bash
, offer ways to write such, but if you want to write a script that works on (nearly) all Unix machines, then you want to stick to the basic features:
#!/bin/sh
n=1
while test $n -le 10
do
...
n=`expr $n + 1`
done
The ...
is the script to be executed 10 times. The expr
command is used to increment the counter by one on each iteration. Notice the spaces, they are important (not the indentation, although I would suggest you keep the indentation proper).
As @Olorin mentioned, the expr
command can also be replaced by:
n=$(($n + 1))
Start Firefox as a background process
start "" "C:\Program Files\Mozilla Firefox\firefox.exe" &
-P user%%n -no-remote imacros://run/?m=we.js
(I broke the line, in DOS script that requires an &
at the end of the line).
Here you start a program using "start" which means it goes in the background. And you specify parameters, one of which uses that counter n
. Assuming firefox is in your path (it will if you installed the default version) then you do not need a full path, just the following:
firefox -P user$n -no-remote imacros://run/?m=we.js &
This is an sh
script where the ending &
is used to start that process in the background. That means the command is started and the shell returns immediately.
You also have a special variable set that gives you the PID of the new process. This could be useful later if you want to send a signal or just know whether the process is still running or not. (i.e. FIREFOX_PID=$!
--in your case, though, you're going to start 10 of them... just one such variable would not work for you.)
Send one quiet ping with a 1.5s timeout
ping 192.168.1.1 -n 1 -w 1500 > NUL
This ping looks like a separate line of code. The -n 1
is to repeat one time and the -w 1500
to specify the timeout. The -w
is one to one equivalent on Linux. The -n
(number), however, has to be replace by -c
(count). Finally, the NUL
special file can be replaced by /dev/null
.
ping 192.168.1.1 -c 1 -w 1500 > /dev/null
Note: to make ping quiet, you can also use -q
as in:
ping 192.168.1.1 -q -c 1 -w 1500
Of course, if the ping
is part of the Firefox command line (unlikely) then you probably shouldn't transform it at all.
for ((n = 1; n <= 10; n++))
, the rest of the code remains the same. The extension is up to you: https://askubuntu.com/q/803434/760903 – Olorin Jun 29 '18 at 02:02&
to the end of the command (otherwise the shell loop will wait for each instance to close before continuing). – steeldriver Jun 29 '18 at 02:44