0

Presently we are using this Batch Script Counter into the Windows Environment, but we need to convert the same one into a Shell Script for Nix Environment.

What are the things need to be Change ?

setlocal enabledelayedexpansion
set /a n=0
set /a m=0
set /a nline=1
set /a mod=0
for /f %%i in (C:\VariableList\Variable.txt -> /home/Variable/AvailableList) do (
  set /a n=m+1
  set /a m=n
  set /a mod=m%%%nline%
  if !mod! EQU 0 (
    run -n -D %%I
    if !ERRORLEVEL! NEQ 0 (
      goto end
    )
  )
)
:end
endlocal
  • 2
    That has to be the most complicated way I've ever seen to run a program with the first line of a file as a parameter. The entire thing can be a one-liner. – SomethingDark Apr 10 '17 at 11:03
  • 1
    The whole thing makes no sense, it doesn't do what you say it does, despite the fact you informed us that it's presently in use. Try just telling us what you want the script to do by editing the original question, then remove the batch-file tag. – Compo Apr 10 '17 at 11:09
  • 2
    Wait, it doesn't even do _that_, it just prints out each line (once you correct the `for` loop variable)(the whole thing can still be a one-liner). Regardless, I wrote a section in Documentation about [batch commands and their bash equivalents](http://stackoverflow.com/documentation/batch-file/8362/differences-between-batch-windows-and-terminal-linux#t=201704101111547385148) that you should read. – SomethingDark Apr 10 '17 at 11:13
  • 1
    I don't think that is your own code. You should search this site for some shell answers for example [this one](http://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash) –  Apr 10 '17 at 11:15
  • https://ss64.com/bash/ – Squashman Apr 10 '17 at 12:43
  • @ShankarMajumder: First, you didn't explain what target language you want to have (Posix Shell, Goode Olde Bourne Shell, bash, Zsh, ksh, fish, ...). Second, I highligh recommend to not *change* a Windoze Batch script into a reasonable scripting language. You define instead what the resulting script is supposed to do, and then *write it from scratch*. The languages are too different to bother with a simple line-by-line translation. – user1934428 Apr 10 '17 at 15:28
  • 1
    @user1934428 - Ordinarily, I'd be all for a complete rewrite over a port of basically anything, but the fact of the matter is that this script is just so _ludicrously straightforward_ that any attempt to rewrite it would just be a translation of the existing script anyway. – SomethingDark Apr 10 '17 at 23:01
  • Hello S.Dark, can you please explain that how it could be a one liner code ? – Shankar Majumder Apr 11 '17 at 09:11
  • @ShankarMajumder: Did you read the **excellent** documentation SomethingDark refered too? After reading this, please ask concrete questions with which part of the translation process you are struggling. – user1934428 Apr 11 '17 at 15:56

0 Answers0