This page has some tips about converting DOS batch files to
bash.
http://www.tldp.org/LDP/abs/html/dosbatch.html
But if you really want to code "standard" scripts, then you have to restrict all of your code to what's available in the POSIX standard. When you run a script with "
#!/bin/sh" at the top, it will be interpreted as such, even if the underlying interpreter is actually
bash or another shell.
Conversely, to get the full set of
bash features, you have to use
#!/bin/bash.
POSIX doesn't have many of the useful modern features that are available to
bash, such as arrays. See this page for bash-specific commands and their equivalents.
http://mywiki.wooledge.org/Bashism
Note: If your script does include things like arrays, and they seem to work, that's only because the system is still set to use
bash (or a similar shell) to do the interpreting. Since arrays are not counter to POSIX, but just
undefined by it, there's nothing keeping a shell from interpreting them if it wants to. But if, for example, the system was using
dash instead (a strictly complying shell), it would break. All
/bin/sh says is that, if a script is coded according to POSIX, it will run. It doesn't try to force compliance to it.
In fact, one of the best ways to test that your script is POSIX-compliant is to use
#!/bin/dash as your shebang. If it runs in
dash, it should run anywhere.
Incidentally, I see several errors in the above script. Unquoted variables, improperly formatted array expansions,
Useless Use Of Cat. But maybe I should wait for you to clarify whether you actually need POSIX or not, or whether a
bash-compatible script would do (it is available standard on pretty much every Linux distro, after all). The latter would certainly be much more convenient.
PS: You also really need to supply us with a sample of the
input. We need to see what the files that it's processing hold.