Unix shell code portable enough to work on all shells

Can someone please let me know the coding guidelines along with the sample code for Unix shell scripts using code that can work on most current shells like ksh, bash, csh, etc. In most cases, some of my code written for ksh will not work on regular sh. I want to make my code as portable as possible. Most of my codes will be around [ifs, elifs] and [whiles, fors] and return the code to capture the child shell (basically, they will run SQL scripts for which I want to get some of the return codes, for example, the number of processed lines, return codes , SQL script error codes).

Also can someone tell me which shell code can be easily ported to other shells? Can someone point me to the correct tutorials and / or code samples?

+3
source share
8 answers

Get yourself the 7th edition of the Unix Programmer Manual (Volume 1) and program the shell described there (Bourne). You can go to the System V (Bourne) shell if you find the appropriate manual; it has several additional functions, such as functions that the 7th edition shell did not have, and they are essentially available everywhere. (This is a very conservative position - but it will give you maximum mobility.)

, , , . , GNU grep , . , GNU sed , . script , , .

, POSIX. POSIX , , . , POSIX , $(...) , Bourne. , () .

, Autoconf . , , , m4, .


, , Bourne/Korn/POSIX C Shell. " C-".

+12

, Bourne (sh), C, . Bourne , .

, , sh. , .

, script , .

+4

perl python?

+2
+1
0

Steve Parker Bourne/ Bash , " : " .. .

, bournesh.

http://freshmeat.net/projects/bournesh/

0

You can use Loker to verify that the syntax is POSIX compliant.

0
source

Source: https://habr.com/ru/post/1771246/


All Articles