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

learn more… | top users | synonyms

39
votes
3answers
5k views

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 ...
34
votes
2answers
2k views

$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?
30
votes
2answers
1k views

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 ...
23
votes
1answer
894 views

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 ...
22
votes
3answers
501 views

shellcheck is advising not to use basename: why?

I am trying out shellcheck. I have something like that basename "${OPENSSL}" and I get the following suggestion Use parameter expansion instead, such as ${var##*/}. From the practical point of ...
22
votes
3answers
2k views

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?
21
votes
4answers
1k views

Is the shell permitted to optimize out useless terminating commands?

If a shell is asked to perform a probably useless (or partially useless) command known to terminate, such as cat hugeregularfile.txt > /dev/null, can it skip that command's execution (or execute a ...
19
votes
4answers
919 views

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 ...
14
votes
3answers
602 views

Newlines in filenames

I understand and accept the premise that defensive1 shell scripting is both prudent and, in the longer term, more sustainable. Many of the answers to text processing questions here follow this ...
14
votes
2answers
941 views

Portability of “> /dev/stdout”

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., ...
14
votes
2answers
2k views

How can I test for POSIX compliance for shell scripts?

Probably the main thing that this website has taught me so far is the importance of writing portable shell scripts. Considering that POSIX is the closest thing to a common standard between all ...
13
votes
4answers
743 views

keep duplicates out of $PATH on source

I have the following code that's source-d by my .shellrc PATH="${PATH}:${HOME}/perl5/bin" PATH="${PATH}:${HOME}/.bin" export PATH but if I make changes to other code and then source this file, my ...
12
votes
2answers
1k views

Why do some applications use ~/.config/appname for their config data while others use ~/.appname?

I've noticed that some applications put their configuration files to ~/.config/appname while others use ~/.appname (the classic way, AFAIK) for this. What's the sense in this distinction and what ...
11
votes
2answers
2k views

How do I test to see if an application exists in $PATH?

I'm trying to write all of my sh startup/env scripts to work with as much DRY and as much: "works on every *nix I clone it to", as possible. This means making sure that if I try to run code that's not ...
8
votes
4answers
720 views

What is meant by “a system call” if not the implementation in the programing language?

I would like to understand the term "system call". I am familiar that system calls are used to get kernel services from a userspace application. The part i need clarification with is the difference ...
8
votes
3answers
98 views

POSIX compliant way to work with a list of filenames possibly with whitespace

I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
7
votes
1answer
183 views

Does POSIX guarantee that the standard utilities are in PATH?

In the "Command Search and Execution" section, the POSIX specification says that PATH is searched when finding a utility to execute (with some exceptions). Does the specification mention anywhere ...
6
votes
2answers
383 views

Where can I find official POSIX and UNIX documentation?

I am looking for official documents on all POSIX standards and specifications. I would like to be able t read the docs to get a better understanding of UNIX systems and how they work at a low level. ...
6
votes
2answers
219 views

What is difference between [ and [[ in BASH? [duplicate]

Possible Duplicate: using single or double bracket - bash When should I use a single bracket? [ When should I use double brackets? [[ Are both POSIX compliant?
6
votes
1answer
689 views

What does 'uni' mean in unistd.h

What does uni mean in unistd.h Does it mean unix? or universal? What is it?
5
votes
4answers
2k views

sed on OSX insert at a certain line

So I've been using 'sed' on linux for a while, but have had a bit of difficulty trying to use it on OSX since 'POSIX sed' and 'GNU sed' have so many little differences. Currently I'm struggling with ...
5
votes
4answers
550 views

Is there a difference between these two commands?

cat a > b and cp a b If they are functionally the same for all intents and purposes, which one is faster?
5
votes
1answer
433 views

A minimal POSIX conformant operating system

For educational purposes, I'd like to start with a POSIX compliant base, including a shell, basic utilities, and an ANSI C compiler, then see what kind of environments I can build by putting packages ...
5
votes
1answer
998 views

A couple arithmetic related commands, Dash, POSIX shell, sh, Increment

When pre/post incrementing a variable, in POSIX Shell, what is the difference between these two examples. They seem like they would have the same consequences, but would they be used differently? ...
5
votes
2answers
56 views

Nested POSIX groups in Linux [duplicate]

If I want to add all of the members who belong to the supplemental group web_users to the apache group (as an additional supplemental group) can I just add web_users group to the apache group? Or do ...
5
votes
1answer
36 views

IO and other shell commands when a program is not started by a terminal

I have several launchers on my desktop for various programs, and there is a "run in a terminal" setting for those launchers. When I check that setting, the program runs from a terminal, and logs its ...
5
votes
2answers
462 views

POSIX find all local files

I'm trying to write a cross-platform command line that will find all local files on a file system. My intention is to use the find command, using only POSIX parameters. Is there a way to skip ...
4
votes
3answers
367 views

Should a serious student of *nix choose a distribution that is POSIX-compliant to learn standard features well?

I want to learn Unix or Linux as a serious student, and specifically want to learn the basics well so that I can have proper understanding and so I can move between platforms and distributions without ...
4
votes
2answers
120 views

Which is the most portable of sed, awk, perl and sh?

Can someone put these tools in order of portability? Which of these is certain to be found on even the most minimal *nix systems? Is any of them 100% sure to be present? My guess is that the order is ...
4
votes
3answers
349 views

Are there “esoteric” (weird) but standards-compliant C compilers or runtimes?

As we know, the C standard does not specify a lot of details of the implementation, for example value of NULL pointer, order of bits and bytes (endiannes), alignment in structs and of stack ...
4
votes
2answers
287 views

What would break if the C locale was UTF-8 instead of ASCII?

The C locale is defined to use the ASCII charset and POSIX does not provide a way to use a charset without changing the locale as well. What would happen if the encoding of C were switched to UTF-8 ...
4
votes
3answers
212 views

Why is there a type for process ids (pid_t), but not for file descriptors (fd)?

I see that pid_t is typedef'd in unistd.h, and file descriptors are defined to be int in fcntl.h. But since they are used in similar ways, wouldn't it make sense to have a typedef for file ...
4
votes
3answers
258 views

OS X/Linux one-liner/script to find the largest recurring group of lines in a text file?

I have a log containing an execution trace where there is infinite recursion eventually terminating when the stack is too deep. There are enough lines and valid included recursion within the larger ...
4
votes
1answer
113 views

Why not just use standard streams instead of using filenames?

While I understand that programs like mv need an actual filename as a parameter, programs like sort could just read from standard input and write to standard output like names | sort > names ...
3
votes
1answer
135 views

the return built-in

According to the Open Group, [t]he return utility shall cause the shell to stop executing the current function or dot script. If the shell is not currently executing a function or dot script, ...
3
votes
2answers
119 views

POSIX test and -a

I checked a script of mine with checkbashisms and I got the following warnings: possible bashism in check_ssl_cert line 821 (test -a/-o): if [ -n "${ALTNAMES}" -a -n "${COMMON_NAME}" ] ; then In ...
3
votes
2answers
175 views

How to monitor the last PID assigned by the kernel?

To monitor process creation I'd like to periodically write the last PID assigned by the kernel to any process on the system (not just processes created by the PID-monitoring program) with a time stamp ...
3
votes
1answer
104 views

Using shell's read command with live editing functionality (readline like)

Is there a standard (POSIX) way of asking the user some data from within a shell script, with read for example, while allowing live edition of the text being typed (what readline does)? I know bash ...
3
votes
1answer
52 views

Common flag designations and standards for shell scripts and functions

I have been adjusting to using GETOPT and GETOPTS in my shell scripts and custom functions to enable me to use the functions that I create more flexibly. After using a number of UNIX functions I have ...
3
votes
2answers
100 views

Shell-independent way to cp dotfiles from a folder to another [duplicate]

I have two existing directories : foo: directory with dotfiles in it foo2: empty directory I would like to have a solution to copy all dotfiles in foo to foo2. I would like a solution that is not ...
3
votes
2answers
311 views

Replace a pattern in a file with a long string

I'm writing a little shell script to generate a directory listing. To make the output easily customizable, the script just builds a HTML-table and than should replace a specific token in a template ...
3
votes
1answer
813 views

Obtain device name and mount point if partition label is known

How to obtain the partition device name and mount point when the file system label is known? There are several possibilities: Linux File system label to device name The device name can be obtained ...
2
votes
1answer
67 views

Are “mostly POSIX-compliant” systems still considered POSIX systems?

Irix and OS X are POSIX systems because they are fully-POSIX-compliant. However, operating systems like FreeBSD, Haiku, and GNU/Linux, for example, are "mostly-POSIX-compliant". Can people still ...
2
votes
3answers
101 views

Why are POSIX Find Parameters Different from Other Program styles?

Why is a parameter in the POSIX find command added with a single hyphen for multi-character parameter names, while most other programs use single hyphen to indicate multiple single-character flags, ...
2
votes
3answers
80 views

Is it shell portable to run a command on the same line after variable assignment?

Is there any standard that covers the portability of running a command after variable assignment on the same line? APPLE="cider" echo hi How portable is something like that? Where will it work and ...
2
votes
2answers
62 views

Read umask for a user

Plenty of examples on how to set umask for a user... but how do you read (or uncover) the default umask for a given user (say the logged in user)
2
votes
1answer
493 views

Why is brk(0) called?

On a first shell I run the command tail with no argument. On a second shell I kill the first tail using strace to monitor the system calls. qdii@nomada ~ $ strace kill 1713 execve("/bin/kill", ...
2
votes
1answer
170 views

Why does the local::lib shell code use eval and $()

using local::lib requires you to add a line to your ~/.shellrc eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib) I don't understand what the point of using eval, and encasing the statement in $() ...
2
votes
1answer
60 views

Awk regular expression syntax with number of repetition - different handling between gawk 3 and gawk 4

I am having trouble understanding or explaining why the following expression fails in gawk 3.1.x and yet works in gawk 4.1.x: (Minimum working example) echo ";#ADCDE#" | awk '/#.{5}#$/' -> produces ...
2
votes
2answers
118 views

what happens when a window manager is put to background

I am trying to understand the situation why .xsession file expects the last process to be in foreground otherwise it is supposed to stop X11 session. I have a small stand-alone script. when I run ...