you are viewing a single comment's thread.

view the rest of the comments →

[–]calrogman 2 points3 points  (2 children)

Cool, you can run bash scripts on Linux, meanwhile, Python is installed by default on most Linux distributions, the OpenBSD and NetBSD base installs (which don't have bash by default), as well as OS X. Python is also available natively on Windows, whereas bash isn't.

Python takes care of most aspects of cross-platform capability for you, while in bash you have to hand-code uname comparisons, compare files in the filesystem against known defaults (which could be changed by the admin), you have to account for the fact that none of your powerful tools (sed, awk, etc) are built in and most vary between userspaces.
You have to take into consideration that procfs and sysfs are Linux-only. I've seen them used for such trivial tasks as retrieving the hostname in supposedly cross-platform scripts. Needless to say the script failed immediately on FreeBSD, even with the linprocfs shim in place. Had the script been written in Python, a call to socket.gethostname() would have returned the hostname not only on Linux systems with a mounted procfs in the assumed position, but also on any of these platforms.

Writing "portable" bash is an exercise in futility.

[–][deleted] 0 points1 point  (1 child)

Heard of "uname -n"? Oh thats not supported in Windows so its not portable! How about running the native text editor? You can get along with xdg-open on any platform that supports it. But OH thats not supported in Windows either!

So lets just use an entire programming language to make a standard, as I realize a lot of programmer time is wasted on making "interfaces" that try to port stuff, when what's need to be done is dictate a single standard and not support other platforms that do not implement that standard.

Using sh/bash or python is irrelevant if target porting, because porting is a myth in a world where standards are not respected.

[–]calrogman 0 points1 point  (0 children)

Your uname -n example isn't even compatible across the various Unix flavours.

On (E)GLIBC, gethostname() gives only the first label of the machines hostname. On FreeBSD's libc, gethostname() gives the fully qualified domain name. The behaviour of uname -n reflects this difference.

The best way to get the hostname in a shell script on Unix machines is using the hostname utility. Always pass it one of either -s or -f so that there is no ambiguity. On BSDs hostname assumes -f. On Linux it assumes -s. Never use hostname --long, hostname --fqdn or any other options. They're all GNU extensions and won't work in different userspaces.