Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Dingo
- Posts: 2
- Joined: 21 Dec 2019 23:37
- Location: Australia
-
Contact:
#1
Post
by Dingo » 21 Dec 2019 23:51
I have a Linux script that I got to work on Ubuntu but I need the same script to run on Windows. The main bit from the Linus script is
Code: Select all
n=100;
max=200;
while [ "$n" -le "$max" ]; do
echo "$passwd"> /usr/bin/multiboinc/BOINC_"$n"/gui_rpc_auth.cfg;
echo "BOINC_$n $passwd";
n=`expr "$n" + 1`;
done
I have tried a bunch of things but I do not know the syntax in Windows. This is what I eventually had:
Code: Select all
set /P passwrd=aussie
echo $passwrd
FOR /L %X IN (100,1,102) DO (
break> /mnt/c/multiboinc/BOINC_"$n"/gui_rpc_auth.cfg;
echo $passwd> C:\multiboinc\BOINC_$X\gui_rpc_auth.cfg
echo BOINC_$X
X=`expr $X + 1`)
DONE
but it gives an error message
C:\multiboinc>passwd_change.bat
C:\multiboinc>set /P passwrd=aussie
aussie
C:\multiboinc>echo $passwrd
$passwrd
C:\multiboinc>set /A X=0
X was unexpected at this time.
C:\multiboinc>FOR /L X IN (100,1,102) DO (
-
aGerman
- Expert
- Posts: 4654
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 22 Dec 2019 08:33
The error is about a SET /A statement that you don't have in your snippet anymore.
Try:
Code: Select all
@echo off &setlocal
set /p "passwrd=Enter your password: "
set /a "n=100,max=200"
setlocal EnableDelayedExpansion
for /l %%X in (%n%,1,%max%) do (
if not exist "C:\multiboinc\BOINC_%%X\" md "C:\multiboinc\BOINC_%%X"
>"C:\multiboinc\BOINC_%%X\gui_rpc_auth.cfg" echo(!passwrd!
)
endlocal
FWIW: In case you are on a Win10 64Bit you can install the Windows Subsystem For Linux (WSL) and run your Linux Shell script as is.
Steffen
-
Dingo
- Posts: 2
- Joined: 21 Dec 2019 23:37
- Location: Australia
-
Contact:
#3
Post
by Dingo » 23 Dec 2019 02:13
Thanks that works like a charm:
I have an old laptop with windows 10 that does not have much space left so just need a script for that. I will also put this code on our forum for those that do not know anything about Linux.
Thanks again. I have another script that I am trying to run and if I still can't get it to work by bedtime I will post again.