Tuesday, January 10, 2017

Re: [LINUX_Newbies] UNIX Compatibility Question

 

On Tue, Jan 10, 2017 at 2:58 PM, Scott scottro@nyc.rr.com
[LINUX_Newbies] <LINUX_Newbies@yahoogroups.com> wrote:
>
> The answer is that most things run on the BSDs, but not all, and they
> frequently have to be somewhat re-written.

More specifically, anything that runs via an interpreter should be ok
in MOST cases (caveat emptor) such as Java, Python, etc.

Things that directly make system calls directly should (again caveat
emptor) work if they adhere to POSIX standards, and things that make
non-POSIX system calls will need porting.

A good demonstration of this (using an interpreted language and
without diving into compiled code that I haven't written in forever)
is the following, very simple code:

bladernr@galactica:~/development$ cat bashtest.sh
# test of a bashism, run this in bash and in sh to see the difference

function bash_function { echo I only work in BASH; }

posix_function() { echo I work in any POSIX shell; }

bash_function || echo Y U NO WRITE POSIX CODE???!?
posix_function || echo Y UR POSIX EXAMPLE FULL OF FAIL!???
bladernr@galactica:~/development$ bash bashtest.sh
I only work in BASH
I work in any POSIX shell
bladernr@galactica:~/development$ sh bashtest.sh
bashtest.sh: 3: bashtest.sh: function: not found
bashtest.sh: 7: bashtest.sh: bash_function: not found
Y U NO WRITE POSIX CODE???!?
I work in any POSIX shell
bladernr@galactica:~/development$ dash bashtest.sh
bashtest.sh: 3: bashtest.sh: function: not found
bashtest.sh: 7: bashtest.sh: bash_function: not found
Y U NO WRITE POSIX CODE???!?
I work in any POSIX shell

Note that posix_function works in all three, where bash_function is
not POSIX compliant and only works in BASH.

Cheers,

Jeff

__._,_.___

Posted by: J <dreadpiratejeff@gmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.

To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.

.

__,_._,___

No comments:

Post a Comment