Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.unix.shell Subject: Re: Which shell and how to get started handling arguments Date: Mon, 15 Apr 2024 14:31:38 -0700 Organization: None to speak of Lines: 35 Message-ID: <8734rms479.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Mon, 15 Apr 2024 23:31:38 +0200 (CEST) Injection-Info: dont-email.me; posting-host="73a59417e165fb25aa14cac8ac742e2a"; logging-data="535702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+0xSXhawBqxv/Zl6w6C52Y" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:oB/W0+h4CnWEXxvpdVmFkt+Ioog= sha1:0NMQw3LtLd2wNwTzxQ1ScN/1A1Y= Xref: csiph.com comp.unix.shell:25068 Lew Pitcher writes: > On Mon, 15 Apr 2024 13:22:14 +0100, James Harris wrote: >> For someone who is relatively new to Unix shell scripting (me) some >> advice would be more than welcome on where to begin. >> >> I have two main queries: >> >> >> Q1) How can one write a script which is maximally compatible with >> different systems? > > As others have said, write your script to the POSIX shell language > standards. (see > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) > > Most shells support this restricted dialect. Bash has an option that tells it to (attempt to) restrict itself to POSIX semantics: Starting Bash with the '--posix' command-line option or executing 'set -o posix' while Bash is running will cause Bash to conform more closely to the POSIX standard by changing the behavior to match that specified by POSIX in areas where the Bash default differs. I haven't used this option myself, and I don't know just how closely it actually conforms to POSIX. I'm less familiar with ksh and zsh, but they probably have similar options. At least the "MirBSD Korn shell" has "set -o posix". -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */