Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [portability]

The tag has no usage guidance.

0
votes
1answer
61 views

Wildcards/Globbing: Are character ranges problematic?

In The Linux Command Line William Shotts claims that character ranges can be problematic. See the relevant excerpt below, emphasis is mine. Character Ranges If you are coming from another Unix-...
1
vote
1answer
37 views

Portable way to run command without PATH from bash script

cron calls my bash script (it's a backup script) with a very sparse PATH of /usr/bin:/usr. As a result, while a line like lvcreate --size 1G --snapshot ... works just fine when I run the script from ...
3
votes
2answers
69 views

Recommended way of checking only one running service?

I am writing a shell script to check if mongod server is running and if not, to start it. To acheive that I am using the below command: systemctl is-active --quiet mongod This does the job as ...
27
votes
3answers
2k views

Porting Linux to another platform requirements [closed]

I know that Linux is available and has been ported for many different platforms such as for X86, ARM, PowerPC etc. However, in terms of porting, what is required exactly? My understanding is that ...
1
vote
1answer
109 views

How does glibc within a Docker image survive different container host kernels?

Docker containers share the kernel of the host, but they do include their own applications and libraries. Is it correct that glibc is one of these libraries? If so, how come there is no problem of ...
7
votes
4answers
529 views

Portable check empty directory

With Bash and Dash, you can check for an empty directory using just the shell (ignore dotfiles to keep things simple): set * if [ -e "$1" ] then echo 'not empty' else echo 'empty' fi However I ...
2
votes
1answer
58 views

All-round 100% portable terminal color support check

Test for terminal color support using tput #!/bin/sh colors_supported() { command -v tput > /dev/null 2>&1 && tput setaf 1 > /dev/null 2>&1 } I am currently using ...
3
votes
0answers
44 views

What subset of Linux does recent WSL support? [closed]

I know well Linux but nothing about WSL or Windows. I'm using Linux since 1993, but I never used Windows (and probably won't use it before my retirement, e.g. before 2024, so I am likely to never use ...
3
votes
3answers
972 views

Do all different Linux distributions have the same command lines? [closed]

Do all different Linux distributions have the same command lines? What I want to know is the same command line works for all kinds of Linux distributions (CentOS, Fedora, Ubuntu, etc.) or whether they ...
2
votes
3answers
76 views

What makes a Linux distro portable? [closed]

What could possibly prevent me from detaching my current hard disk from the laptop and buy a new laptop, install the disk and resume from where I left? In other words, what prevents my current Debian ...
1
vote
0answers
203 views

Why should anyone ever put anything in /etc/zshenv or ~/.zshenv? [closed]

There is already a question "What should/shouldn't go in .zshenv, .zshrc, .zlogin, .zprofile, .zlogout?". I'm wondering why anyone ever puts anything in /etc/zshenv or ~/.zshenv. For those who are ...
4
votes
3answers
573 views

Can I read a single character from stdin in POSIX shell?

Only read -r is specified by POSIX; read -n NUM, used to read NUM characters, is not. Is there a portable way to automatically return after reading a given number of characters from stdin? My usecase ...
0
votes
1answer
32 views

Portable way to run a simple script at startup

I'm trying to run a script at startup as root. (Just sets up a root-owned directory in /tmp). Currently, I'm using this script to set up the boot hook and it appears to get the job done: #!/bin/sh -...
-3
votes
1answer
88 views

Is pstree available on all Unices and Linux operating systems? [closed]

Is it a standard command that I can be assured is available on all standard-conformant operating systems? If so, what is the guarantee given by the relevant standard? Is it, conversely, a non-...
3
votes
0answers
64 views

What's wrong with putting do on the same line as for? [duplicate]

While reading about 11.12 Limitations of Shell Builtins I came across the following: To loop over positional arguments, use: for arg do echo "$arg" done You may not leave the do ...
3
votes
2answers
118 views

Is word splitting a part of POSIX?

I know that Bash has word splitting but zsh doesn't, and I'm not familiar with others(csh, tcsh, ksh, etc), but I was wondering if it is a part of any standard. In other words, does sh have word ...
3
votes
1answer
254 views

How to change the RS variable in AWK between files in a portable way

While looking at another question, I came across a problem I couldn't solve generally for awk, where if an awk program takes two files (i.e. to read entries from the first into an array to compare ...
1
vote
1answer
343 views

Availability of deprecated egrep and fgrep commands

Quite often I've seen answers mentioning that egrep is grep -E or fgrep is grep -F and using egrep or fgrep in their answers, even though these are technically deprecated. So I was wondering if ...
2
votes
2answers
83 views

How to locate one or more underlying disks when you know only a directory?

Assume that I have some device mounted to /backups. I'm copying selected files from the system to backup and I would like to reduce the amount of noise the device is making. I know that I can can use ...
0
votes
0answers
40 views

Portably determine listen ports in shell script

I have an init script for an application, and know the PID is available from the script. I am trying to add some logic to the status command to output the TCP listen ports associated with the PID. I ...
3
votes
2answers
629 views

Is the use of sed's “a” command to prefix a line portable?

I noticed the following interesting behavior: $ printf '%s\n' line{1..2} | sed $'1a\\\nPREFIX' line1 PREFIXline2 $ Interestingly, this behavior is only possible for the last command in a Sed script,...
1
vote
2answers
572 views

select(2) on FIFO on macOS

On Linux the included program returns from select and exits: $ gcc -Wall -Wextra select_test.c -o select_test $ ./select_test reading from read end closing write end first read returned 0 second read ...
2
votes
1answer
387 views

Multiple arguments in shebang lines

Linux only supports one argument in a shebang line: This: #!/bin/sh cat > pr_args <<'EOF' #!/bin/sh -e printf "'%s'\n" "$@" EOF cat > shebang <<'EOF' #!pr_args a b c EOF chmod +x ...
0
votes
0answers
80 views

Any *nix variant withOUT `/bin/cat`?

I'm writing a simple regression test for a tool like which(1) and someone pointed out there's no guarantee that there is always /bin/sh (AIX seems to have sh(1) as /usr/bin/sh, for example) and we ...
0
votes
3answers
265 views

How do I convert a relative to an absolute path, portably and robustly?

Suppose I'm running bash on a Unix-ish system - not necessarily Linux and not necessarily very new; and it may not have every bit of software I'd like. Now, I have a relative path for which I want to ...
10
votes
1answer
329 views

Do shells other than Bash and Zsh support ANSI-C quoting? e.g. $'string'

I have a shell script that uses the following to print a green checkmark in its output: col_green="\e[32;01m" col_reset="\e[39;49;00m" echo -e "Done ${col_green}✓${col_reset}" After reading about ...
1
vote
1answer
69 views

How to make an Ubuntu flashdrive portable to different computers? [closed]

I installed Ubuntu on my USB stick and everything works as expected on my main PC, but when I connect the USB stick to my laptop and try to boot it gets stuck in a boot-loop at the loading screen. ...
7
votes
4answers
990 views

What's the safest, most portable way to invoke the echo binary?

The echo in coreutils seems to be ubiquitous, but not every system will have it in the same place (usually /bin/echo). What's the safest way to invoke this echo without knowing where it is? I'm ...
7
votes
3answers
6k views

stat: modification timestamp of a file

I use stat -f %m .bashrc to get modification time of my .bashrc on osx. But when I run the same command on ubuntu, it spits error: stat: cannot read file system information for %m': No such file or ...
9
votes
5answers
3k views

Universal non-bash `time` benchmark alternative? [closed]

For comparing run times of scripts between different shells, some SE answers suggest using bash's built-in time command, like so: time bash -c 'foo.sh' time dash -c 'foo.sh' ...etc, for every shell ...
1
vote
0answers
562 views

How to run .phar file with PHP CLI from an unpacked RPM?

How to reproduce: "Install" PHP 5.4 (plus ncurses and OpenSSL libraries) from CentOS 7 repositories using rpm2cpio | cpio in a directory called "rpm" Download phpunit.phar version 4.8.26 Run ...
0
votes
1answer
174 views

Equivalent in Mono on Linux of GetUpdateRect on Windows?

I'm trying to compile in Mono on Lubuntu 16.04.1 a very helpful open-source Windows program, "Ketarin". It uses a function, "GetUpdateRect", which it finds in user32.dll, using this code: [...
1
vote
2answers
407 views

Widespread support for find with “-exec … +”? [closed]

Judging from the GNU findutils change log it had to be in GNU's find for at least a decade (also longer than that it was part of POSIX) so can it be safely assumed to be supported everywhere now? ...
1
vote
2answers
65 views

Need to update shell scripts so they can run in different *nix flavors

I have a bunch of ksh and csh scripts that need to be updated to run in different *nix flavors (red hat linux, hp ux, solaris). The shells are mounted in the home of each of our servers and we need ...
2
votes
1answer
635 views

Will an `unlink` or `rename` portably and atomically make a `link` fail?

Question Suppose I have some non-directory (file, named pipe/socket, whatever) at the pathname /tmp/foo and some other non-directory at the pathname /tmp/bar. Then two (or more) processes start ...
2
votes
3answers
446 views

Portable one-byte per line hex dump

Suppose we want a minimalist one-byte per line ASCII hex dump. Under Linux using GNU od, this works: echo foo | od -An -tx1 -w1 -v Output: 66 6f 6f 0a But that won't work with BSD derivatives,...
3
votes
3answers
138 views

Is it portable to indent the argument to sed's 'i\' command?

I was under the impression from the POSIX specs for sed that it is necessary to left-align the text on the line following the i\ command, unless you want leading whitespace in the output. A quick ...
11
votes
1answer
3k views

Are /dev/{udp,tcp} standardized or available everywhere?

I've recently learned about the /dev/udp and /dev/tcp pseudo-devices here. Are they specific to some GNU/Linux distributions or can I find them on other unix systems? Are they standardized in some ...
1
vote
1answer
84 views

is it okay to assume my commands in use are exist by default with almost all distributions

I'm maintaining a small USB device driver code for Linux. This is a user mode code so , there are places that we need to find what is the version of libudev so and etc. So the only way that I came up ...
1
vote
3answers
76 views

does arch exist on all linux/unix systems?

Trying to find the most portable way to determine the CPU architecture of a system, be it 32bit x86, 64bit or something else (e.g. ARM). does the arch command exist on all systems? otherwise how do I ...
15
votes
7answers
9k views

Are binaries portable across different CPU architectures?

My goal is to be able to develop for embedded Linux. I have experience on bare-metal embedded systems using ARM. I have some general questions about developing for different cpu targets. My questions ...
6
votes
3answers
713 views

Portable POSIX shell alternative to GNU seq(1)?

I've noticed you can't really count on seq(1) being available on anything but GNU systems. What's a simple reimplementation of seq(1) I can bring with me written in POSIX (not bash) shell? EDIT: Note ...
5
votes
2answers
285 views

Is getopts always available for Bash?

Can I use getopts for parsing command-line arguments in my bash scripts(not sh) without worrying about another depedency?
3
votes
1answer
228 views

A common way of combining two files in Solaris and Linux

I am trying to write a script that would combine two files into one and should work in both Solaris 5.10 and a Linux box. File1: dit710 dit710 dit720 dit720 File2: FacA D0000000000000001 FacA ...
3
votes
1answer
9k views

How / Is it possible to install python in a portable way?

I'm working on a python script which takes care to migrate a mysql database with a certain schema / structure, into a postgresql database with a different structure. During the development phase I ...
11
votes
3answers
4k views

sending output to /dev/stderr vs. >&2

In scripts, errors are usually sent to file descriptor 2 with &2, ie: echo "error" >&2 Sometimes /dev/stderr is used instead: echo "error" > /dev/stderr Looking at /dev/stderr, I ...
3
votes
2answers
137 views

avoid multiple pipes broken due to missing command

In shell scripts I often use multiple pipes like this: cmd1 | cmd2 | cmd3 Now if cmd2 is missing the pipe will result "broken" and cmd3 won't receive any input. As workaround I could test ...
2
votes
3answers
1k views

Predefined group ids across Linux distros?

In order to successfully implement w/r access via ACL for external storage with ext4 fs I need to assign default group id for files on storage. LSB_5.0.0 say: This specification makes no attempt to ...
4
votes
1answer
129 views

Bash script for showing newly introduced env variables

I'm making this test script to help me reverse engineer scripts in charge of setting the dev environment. The script: #env-changes #!/bin/bash TESTED_SCRIPT=$1 shift ENV_BEFORE=$(env | sort) . $...
17
votes
4answers
1k views

checkbashisms-compliant way to determine the current shell

In my .profile, I use the following code to ensure that Bash-related aliases and functions are only sourced if the login shell actually is Bash: # If the current (login) shell is Bash, then if [ "${...