It depends on how you've written your shell scripts. A lot of Bash scripts I've seen people create don't really need Bash and will work just fine with
sh(1). And that would be the best way to make your scripts more compatible. Don't use "bashisms" and stick to plain Bourne shell.
I didn't know what bashism even mean, but after a little search it just mean not to use bash, like you said and if I get it right that everything I do in sh is compatible with bash but not vise versa. Am I right?
External commands, like
date(1) are mostly compatible, but as you've already found out can differ in certain details. You either work around those or do things entirely differently (there's usually dozens of ways to come up with a solution).
Yes, date, awk and others made a lot of problems, but my ducktape solution for now is to use coreutils and replace every awk to gawk, date to gdate, etc.
I do not want to sound harsh but If you would write these scripts in POSIX /bin/sh in the first place you would not have that problem.
Being harsh is sometimes even efficient. I've learnt all the shell scripting by searching the net and that's what happens if you just do this. I have never heard of POSIX before and why it might be something good... and this might be a problem with many people learning shell scripting in Linux. But after searching the net it just says it is a standard for shell scripting. Am I getting it right?
You scripts are currently (probably) full of Bashisms and Linuxisms and to make them work on anything other then Bash or Linux you need to remove then. Each one one them.
In your place I would take that chance to rework these scripts to something better with a lot of case statements like this one below:
...
This might be a really good solution, but for testing the scripts I would need two operating systems. Is this the right way to have a compatibility with Linux and FreeBSD? It somehow sounds easier to use Python or other languages, which works on Linux and FreeBSD the same (hopefully it is like that, because I might be wrong about Python).
And on the other hand it just sounds really redundant to learn all the awk, grep, date and coreutils twice and might be really confusing if you switch between Linux and FreeBSD often.
Or is my way of thinking wrong to use a language, which works the same on FreeBSD and Linux?
Feel free to post the Bashisms and Linuxisms so we can help you to port these into proper POSIX /bin/sh code.
I will definitely create a POSIX /bin/sh version with FreeBSD and Linux switches for some scripts I've written and publish them and I really appreciate the help of this community.
Thanks a lot for your help
--------------------
P.S.:
balanga mentioned in another thread to install coreutils to get all the gnu versions, using gawk instead of awk, etc.
You can actually install GNU date if necessary, it is part of
sysutils/coreutils.
Under FreeBSD it is run a
gdate()