View Single Post
Old 18 March 2023, 09:58   #1
EctoOne
Registered User
 
EctoOne's Avatar
 
Join Date: Jun 2020
Location: Germany
Posts: 370
Create a (bash) function in a shell script?

Hi, I'm looking for a way to optimize a script I'm currently working on.

It's purpose is to sort files into alphabetical subfolders. Which basically means that I have to use the same code block 26 times for each (normal) letter. I already have a code block which relies on a variable and therefore it does not have to be altered for each letter. In a bash script I simply could turn that block into a function. Which makes the code easier to change (just one block instead of 26) and it would be much smaller.

The code block looks like this:
Code:
SET Letter "A"
LIST >>T:AlphaSort.${Letter} FILES "${Source}" PAT="${Letter}~(.info)" LFORMAT="${Command} *"%P%N*" *"${Target}${Letter}/*"*nECHO *"*E[43m *E[40m*" NOLINE"
ECHO "*E[43m *E[40m" NOLINE
IF "empty" EQ "`ECHO "*`LIST FILES "T:AlphaSort.${Letter}" LFORMAT="%L"*`" NOLINE`"
  DELETE >NIL: "T:AlphaSort.${Letter}"
ELSE
  ECHO >>T:AlphaSort.EXE "ECHO *"${Action}: ${Letter}#? to ${Target}${Letter}/... *" NOLINE"
  ECHO >>T:AlphaSort.EXE "MAKEDIR >NIL: ${Target}${Letter}"
  TYPE T:AlphaSort.${Letter} >>T:AlphaSort.EXE
  ECHO >>T:AlphaSort.EXE "ECHO *" Done.*""
ENDIF
First the starting letter is set and then all operations are done based around that letter.

I'll attach the current version of the script, so you can check it out completely.
I added the .s extension for it to be a valid file but it is just a normal text based shell script.

Edit: Removed this version. See below for newer version.

Last edited by EctoOne; 18 March 2023 at 13:03.
EctoOne is offline  
 
Page generated in 0.05261 seconds with 11 queries