LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 05-21-2024, 12:47 PM   #1
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557
How can I determine if a script is BSD-compatible?


Short of tediously cross-referencing man pages, is there a way to determine whether a script contains commands/options that either do not exist or behave differently on BSD systems? (Compared to a GNU/Linux system the script was originally intended for.)

For example, neither OpenBSD find nor FreeBSD find has a printf option. Or for OpenBSD rmdir there is no verbose option (to list removed directories), whilst FreeBSD rmdir has only the shorthand -v, so if a script contains --verbose it must be changed.

ShellCheck could do this with the right rules, but "it's not currently supported and there's quite a few details to be worked out". (I'm not sure what those details might be; given appropriate data it seems straightforward to me.)

Do BSD people currently have any methods for handling this?

 
Old 05-21-2024, 01:16 PM   #2
jmccue
Member
 
Registered: Nov 2008
Location: US
Distribution: slackware
Posts: 710
Blog Entries: 1

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
The only way I can think of is test for OS:

OS=`uname -s`

But in reality, if you want the script to be portable, avoid all bash specific items and stick to POSIX.
 
Old 05-22-2024, 09:34 AM   #3
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,628

Original Poster
Rep: Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557Reputation: 2557

My threads always seem to attract responders who clearly haven't read what I actually wrote. It is very frustrating.

-

I expect I will end up having to write something which parses the documentation and/or sourcecode for POSIX/GNU/Busybox/OpenBSD/FreeBSD userland tools to extract a list of commands and supported arguments for each, restructure to a suitable format, then learn enough Haskell to patch ShellCheck with an extra parameter and rule(s) and whatever else is needed.

If I'm lucky maybe someone else will have done that before it next becomes relevant, but I'm not holding my breath.

 
Old 05-22-2024, 12:37 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,046

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
Quote:
Originally Posted by boughtonp View Post
My threads always seem to attract responders who clearly haven't read what I actually wrote. It is very frustrating.
I totally agree with you, that is annoying. From the other hand I don't think that tool is available, at least I have never heard anything similar. If you want to use it on different hosts you need to make it portable, or you need to make it manage all the differences. At least that's what I made. At the end you will get the answer "if you want the script to be portable, avoid all bash specific items and stick to POSIX."
Or another way to use a common language, which works identically everywhere (perl, python, ...).
 
Old 05-22-2024, 12:45 PM   #5
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,522

Rep: Reputation: Disabled
I believe using standard 'sh' rather than one with added features would work as it would be POSIX, which all system should be able to use.

Also, use standard tools such as 'sed', 'awk', 'grep', etc, or as above, 'perl'.
 
1 members found this post helpful.
Old 05-29-2024, 05:15 AM   #6
_blackhole_
Member
 
Registered: Mar 2023
Distribution: FreeBSD
Posts: 105

Rep: Reputation: 90
You should ask your question at the FreeBSD forums.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PC BSD, Open BSD, or Free BSD ? Alexvader *BSD 5 02-08-2010 12:40 AM
How can I determine if my internal card reader is compatible with sdhc cards? ask Linux - Hardware 4 10-31-2008 10:00 AM
Video For BSD --- New project to develop V4L compatible drivers for BSD Fritz_Katz *BSD 5 07-19-2008 11:53 PM
MacOsX, Darwin, *Nix BSD: Can we make linux and Mac compatible for programs ? frenchn00b Linux - General 1 02-17-2008 01:00 PM
How do i determine my IP address? How do i determine my host name? jwymore Linux - Networking 5 02-07-2007 09:57 AM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration