Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
31 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
3answers
322 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
53 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 ...
2
votes
0answers
34 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
559 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
141 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
379 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
29 views

Portable way to run a simple script at startup

I'm trying to run a very simple 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: ...
-3
votes
1answer
76 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
59 views

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

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
110 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
209 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
295 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
82 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
39 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
561 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
517 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
359 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
77 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
167 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 ...
7
votes
1answer
263 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
68 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
958 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 ...
6
votes
3answers
5k 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
487 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
170 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
383 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
59 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
567 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
382 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
130 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
2k 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
8k 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
663 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
263 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
216 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
8k 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
135 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
124 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 [ "${...
0
votes
0answers
407 views

Equivalent to OS X's py2app and Windows's py2exe?

I'm writing an application in Python. I don't expect my end users to be particularly tech-savvy, so I'd like to package it up like a familiar native executable. For OS X, that means running it ...
2
votes
1answer
1k views

how can one manually assign a permanent / static IP address with “ip addr add”?

After an IP address is assigned to this network interface, with any of the the following commands: ip addr add 10.0.0.0 dev eth1 valid_lft forever preferred_lft forever ip addr replace 10.0.0.0 dev ...
110
votes
9answers
9k views

On what systems is //foo/bar different from /foo/bar?

Throughout the POSIX specification, there's provision (1, 2, 3...) to allow implementations to treat a path starting with two / specially. A POSIX application (an application written to the POSIX ...
10
votes
2answers
4k views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...