Questions tagged [posix]

POSIX is an acronym for Portable Operating System Interface, a family of standards specified by the IEEE for maintaining compatibility between operating systems.

POSIX is a family of standards that specify the behavior of Unix-like operating systems.

These standards define:

  • A standard operating system interface and environment.
  • A programming API for the C programming language.
  • The behavior of a command interpreter (or shell).
  • The behavior of common utility programs invocable from the shell.

The POSIX standards are developed by the Austin Group, sponsored by the Portable Application Standards Committee of the IEEE.

The current set of POSIX standards is available online.

642 questions
209
votes
5 answers

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
xenoterracide
  • 57,918
  • 74
  • 184
  • 250
168
votes
4 answers

What exactly is POSIX?

I see POSIX mentioned often and everywhere, and I had assumed it to be the baseline UNIX standard.. until I noticed the following excerpt on a Wikipedia page: The Open Group The Open Group is most famous as the certifying body for the UNIX …
Peter.O
  • 32,426
  • 28
  • 115
  • 163
140
votes
6 answers

difference between "function foo() {}" and "foo() {}"

I can define bash functions using or omitting the function keyword. Is there any difference? #!/bin/bash function foo() { echo "foo" } bar() { echo "bar" } foo bar Both calls to functions foo and bar succeed and I can't see any difference.…
Carlos Campderrós
  • 2,041
  • 2
  • 16
  • 18
110
votes
4 answers

How can I test for POSIX compliance of shell scripts?

Considering that POSIX is the closest thing to a common standard among all unices, I'm interested in knowing if there's a shell that supports it exclusively. While most modern shells provide support for POSIX (and will run POSIX compliant scripts…
rahmu
  • 19,673
  • 28
  • 87
  • 128
107
votes
5 answers

Do progress reports/logging information belong on stderr or stdout?

Is there an official POSIX, GNU, or other guideline on where progress reports and logging information (things like "Doing foo; foo done") should be printed? Personally, I tend to write them to stderr so I can redirect stdout and get only the…
terdon
  • 234,489
  • 66
  • 447
  • 667
86
votes
8 answers

Multiple arguments in shebang

I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /usr/bin/env. The problem I encounter then is that…
Rastapopoulos
  • 1,569
  • 1
  • 10
  • 21
85
votes
3 answers

What is the point of the `cd` external command?

As referenced in this fine answer, POSIX systems have an external binary cd in addition to the shell builtin. On OS X 10.8 it's /usr/bin/cd. You can't use it like the builtin cd since it exits immediately after changing its own working directory.…
kojiro
  • 4,544
  • 4
  • 24
  • 32
75
votes
5 answers

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

Occasionally I need to specify a "path-equivalent" of one of the standard IO streams (stdin, stdout, stderr). Since 99% of the time I work with Linux, I just prepend /dev/ to get /dev/stdin, etc., and this "seems to do the right thing". But, for…
kjo
  • 14,779
  • 25
  • 69
  • 109
60
votes
1 answer

Does 'rm .*' ever delete the parent directory?

The expression .* is expanded by bash to include the current and parent directories: $ ls -la total 2600 drwxrwxrwx 2 terdon terdon 2162688 Sep 10 16:22 . drwxr-xr-x 142 terdon terdon 491520 Sep 10 15:34 .. -rw-r--r-- 1 terdon terdon 0…
terdon
  • 234,489
  • 66
  • 447
  • 667
59
votes
3 answers

What is the portable (POSIX) way to achieve process substitution?

Some shells, like bash, support Process Substitution which is a way to present process output as a file, like this: $ diff <(sort file1) <(sort file2) However, this construct isn't POSIX and, therefore, not portable. How can process substitution be…
starfry
  • 7,302
  • 6
  • 47
  • 69
59
votes
3 answers

Difference between POSIX, Single UNIX Specification, and Open Group Base Specifications?

What are the differences between POSIX, the Single UNIX Specification, and the Open Group Base Specifications? I think their purpose is for determining if an OS is Unix?
Tim
  • 98,580
  • 191
  • 570
  • 977
52
votes
1 answer

When and how was the double-dash (--) introduced as an end of options delimiter in Unix/Linux?

I don't think the shell/utilities in historical Unix nor in something as "recent" as 4.4BSD supported using a double-dash(or two consecutive hyphens) as an end of options delimiter. With FreeBSD, you can see for instance a note introduced in the rm…
user44370
49
votes
8 answers

Why are POSIX mandatory utilities not built into the shell?

The purpose of this question is to answer a curiosity, not to solve a particular computing problem. The question is: Why are POSIX mandatory utilities not commonly built into shell implementations? For example, I have a script that basically reads a…
Kyle
  • 655
  • 6
  • 9
48
votes
7 answers

Is test or [ or [[ more portable both between bash shells and between other shells?

I see I can do $ [ -w /home/durrantm ] && echo "writable" writable or $ test -w /home/durrantm && echo "writable" writable or $ [[ -w /home/durrantm ]] && echo "writable" writable I like using the third syntax. Are they equivalent in all ways and…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
47
votes
4 answers

Why are UNIX/POSIX system call namings so illegible?

What is the reason to use such untelling system call names like time and creat instead of getCurrentTimeSecs and createFile or, maybe more suitable on Unix get_current_time_secs and create_file. Which brings me to the next point: why should someone…
Benjoyo
  • 589
  • 4
  • 5
1
2 3
42 43