A
A
AirFlare2021-07-25 23:42:36
bash
AirFlare, 2021-07-25 23:42:36

How to rewrite this piece of code under BASH?

Goodnight! There are two pieces of code:
1.

FOR %%F IN (assets lib libs unknown) DO (
  if exist "_INPUT_APK\%~1\%%F" (
    FOR /f "tokens=1* delims= " %%a IN ('sfk list -hidden -quiet -quot -relnames "_INPUT_APK\%~1\%%F" -sincedir "_INPUT_APK\%~1\_backup\%%F" 2^>nul') DO (
      if /I %%F==assets (call :copy2 "_INPUT_APK\%~1\assets\%%~b" "_INPUT_APK\%~1\_backup\upd\0\assets\%%~b")
      if /I %%F==lib (call :copy2 "_INPUT_APK\%~1\lib\%%~b" "_INPUT_APK\%~1\_backup\upd\7\lib\%%~b")
      if /I %%F==libs (call :copy2 "_INPUT_APK\%~1\libs\%%~b" "_INPUT_APK\%~1\_backup\upd\7\libs\%%~b")
      if /I %%F==unknown (call :copy2 "_INPUT_APK\%~1\unknown\%%~b" "_INPUT_APK\%~1\_backup\upd\0\%%~b")
    )

2.
if %delete_resources_in_expert_mode%==ON (
    FOR /f "tokens=1* delims= " %%a IN ('sfk list -hidden -quiet -quot -relnames "_INPUT_APK\%~1\_backup\%%F" -sinceadd "_INPUT_APK\%~1\%%F" 2^>nul') DO (
        if /I %%F==assets (echo assets\%%~b>>"_INPUT_APK\%~1\_backup\upd\delete.list")
        if /I %%F==lib (echo lib\%%~b>>"_INPUT_APK\%~1\_backup\upd\delete.list")
        if /I %%F==libs (echo libs\%%~b>>"_INPUT_APK\%~1\_backup\upd\delete.list")
        if /I %%F==unknown (echo %%~b>>"_INPUT_APK\%~1\_backup\upd\delete.list")
      )
    )

The thought in any way cannot come to mind what functions in BASH to implement all this. Don’t kick too hard, I know that I want a lot, but no ideas came to mind ... Unless to use a cycle, but how ...

Answer the question

In order to leave comments, you need to log in

4 answer(s)
H
hint000, 2021-07-26
@hint000

Try to build a construct from find and xargs, in which case the loop is not explicitly required.
lots of examples: https://www.google.com/search?q=find+xargs
If this is not enough, then you can add awk, it will be more complicated, but the possibilities are widest.

C
CityCat4, 2021-07-26
@CityCat4

Take and write. There are loop, conditional, comparison, string parsing operators in bash :)

S
Saboteur, 2021-07-26
@saboteur_kiev

Maybe you don’t need to fence all these cycles at all, but just read the help on rsync and make everything rsync?
It can compare and copy folders and generate a file.

S
SOTVM, 2021-07-26
@sotvm

on your fingers explain what exactly is needed,
I think finde+ xargs{} solves this problem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question