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

0
votes
1answer
50 views

What is the meaning of xargs show limits output

You can use xargs to discover limits about the commandline you're using: $ xargs --show-limits Your environment variables take up 1901 bytes POSIX upper limit on argument length (this system): ...
-1
votes
3answers
52 views

Wrong parameters passed to tar command makes file1 unusable!

Wrong parameters passed to tar command makes file1 unusable!! Correct command to tar file is: $ tar cvf total.tar file1 file2 but upon using the below format I am not able to recover file1 $ tar ...
4
votes
1answer
63 views

Why does Gawk in compatibility mode split records in the same way as when GNU extensions are enabled?

I'm not sure if I found a bug in Gawk or if I'm misreading / missing something in gawk's man page. According to gawk's man page, when in compatibility mode, if RS contains multiple characters, only ...
3
votes
3answers
192 views

POSIX compliance of the cd program?

Is globbing and shell expansion same thing? I'm learning C by writing a custom shell and I'm also learning POSIX. Now I wonder if it is POSIX compliance that cd - takes you back and that ~ means home ...
1
vote
2answers
46 views

What's the POSIX way to read an exact number of bytes from a file?

Just hit this problem, and learned a lot from the chosen answer: Create random data with dd and get "partial read warning". Is the data after the warning now really random? Unfortunately ...
26
votes
5answers
4k 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., ...
34
votes
3answers
9k 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 ...
3
votes
4answers
133 views

Check if a shell variable has more than one line using built-ins?

I can do this by calling the external utility sed (for a known non-empty $myvar) like so: if [ "$(printf %s "$myvar" | sed -n '$=')" -eq 1 ]; then echo "Your variable has only one line, proceeding" ...
1
vote
2answers
82 views

Is `var=value builtin` the same as `var=value; builtin`?

In my answer here, I used the construct: n=$1 shift Reading Token Recognition spec, I understand that the shell will parse that line into two parts - the variable assignment n=$1 and the builtin ...
0
votes
0answers
16 views

Good or best way to compile for “POSIX”? [migrated]

I tried to read the "POSIX standard" that is not very much. If I want to compile "POSIX compatible", is C99 even acceptable or do I have to use flags like gcc -pedantic -Wall -ansi -O3 ?
12
votes
1answer
136 views

POSIX equivalent for GNU timeout?

The GNU coreutils timeout command is extremely handy for certain scripting situations, allowing for using the output of a command if it is quick to run, and skipping it if it would take too long. How ...
3
votes
1answer
49 views

Limit POSIX find to specific depth?

I noticed recently that POSIX specifications for find do not include the -maxdepth primary. For those unfamiliar with it, the purpose of the -maxdepth primary is to restrict how many levels deep find ...
2
votes
1answer
51 views

POSIX Awk sort array

I would like to sort an array with POSIX Awk, however I have discovered that: asort() asorti() PROCINFO["sorted_in"] are all GNU extensions. Can this be done with without GNU Awk?
-1
votes
1answer
25 views

POSIX, Unix, Linux and Minix: What is what? [closed]

I am confused by the many related terms in the topic "UNIX". How are the terms POSIX, UNIX, Linux and Minix related? Which one is the root of all etc...?
1
vote
0answers
17 views

Why do I need an `;` or newline in `echo hi| { cat; }`? [duplicate]

In bash and dash the examples echo hi | { cat ; } and echo hi | { cat } produce the intended result hi. However, echo hi | { cat } is a syntax error $ sh -c "echo hi | { cat };" sh: 1: ...
0
votes
1answer
32 views

How can i remove duplicates from the output of tshark output [duplicate]

sudo tshark -i ppp0 'tcp port 80 \ and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \ -R'http.request.method == "GET" && http.request.uri contains ...
74
votes
4answers
18k 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 ...
0
votes
2answers
43 views

Does filename expansion append a slash to a symbolic link?

From the manual of coreutils: Some GNU programs (at least cp and mv) allow you to remove any trailing slashes from each source argument before operating on it. The --strip-trailing-slashes ...
0
votes
1answer
34 views

How can I access the history buffer in sh? (not in Bash)

Is there a command history in sh, for example how to access it, and as well, how to ensure it is clear? To clarify shells here: let's say you've logged on to a non-Gui Linux system, and $SHELL is ...
0
votes
0answers
51 views

Is a pipeline made of simple commands?

From Bash Reference Manual A pipeline is a sequence of simple commands separated by one of the control operators | or |&. From POSIX 2013 A pipeline is a sequence of one or more commands ...
1
vote
3answers
283 views

Are & and ; unary or binary operators?

About the control operators & and ;, from POSIX 2013: For asynchronous lists, the format for running a command in the background is: command1 & [command2 & ... ] For sequential ...
0
votes
3answers
76 views

How to understand the definition of a simple command?

From POSIX 2013: A ‘‘simple command’’ is a sequence of optional variable assignments and redirections, in any sequence, optionally followed by words and redirections, terminated by a control ...
1
vote
2answers
71 views

How to understand this POSIX description about `(`, `)` and `test`?

From POSIX 2013: The XSI extensions specifying the -a and -o binary primaries and the '(' and ')' operators have been marked obsolescent. (Many expressions using them are ambiguously defined by ...
0
votes
1answer
31 views

Does find Command Do Match For Regexp Because Of Implementation?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and ...
10
votes
2answers
732 views

Is there a POSIX way of setting zeroth argument of a target application?

In bash you can use exec -a and in zsh you can alternatively also set ARGV0 to execute a program with a certain zeroth argument but is there also a POSIX way of doing so? As suggested in this one ...
3
votes
3answers
54 views

How to understand the order between expansions?

From POSIX 7: The order of word expansion shall be as follows: Tilde expansion (see Section 2.6.1), parameter expansion (see Section 2.6.2), command substitution (see Section ...
0
votes
2answers
34 views

What is the difference between token identifier WORD and NAME?

In POSIX 7, the shell grammar (Section 2.10 in XCU) mentions several token identifiers. I am confused about two: WORD and NAME. What are their differences? For example, is a command's option WORD ...
7
votes
1answer
578 views

What does `\time`, `t\ime` and `\cd` actually do? (fun with backslashes in shells)

While discussing over the differences between /usr/bin/time and the shell (bash and zsh) built-in time, someone mentioned that one can use \time as a shorthand to get /usr/bin/time. First it seemed ...
4
votes
1answer
52 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) . ...
3
votes
2answers
53 views

How to source `. filename` reliably?

The current POSIX spec does not specify any options for dot . builtin. If I do something like: $ echo 'echo .' > /tmp/-foo $ PATH=/tmp "$shell" -c '. -foo' then the result is varied between ...
8
votes
2answers
112 views

How to get filesystem info for a specific file?

What is the best way to find out file system information about a file. For example, if I have a file /media/xyz/path/to/file.ext And /etc/fstab contains //server1/Share1 /media/xyz cifs ...
1
vote
2answers
114 views

POSIX print function definition

Bash can print a function defintion: $ bash -c 'y(){ echo z; }; export -f y; export -f' y () { echo z } declare -fx y However this fails under POSIX Bash, /bin/sh and /bin/dash: $ bash --posix ...
0
votes
1answer
51 views

What is the safest (or most elegant or shortest) way to change to the directory from where a script is called?

I wondered what might be a safe or the Unix compatible way to change to the directory from which a script is called. These two methods even work in a directory with spaces and special characters in ...
16
votes
4answers
765 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 [ ...
11
votes
4answers
14k views

find -exec in bash script with variable expansion

I'm trying to run a command similar to the one below in a bash script. It should search through all subfolders of $sourcedir and copy all files of a certain type to the root level of $targetdir. ...
4
votes
1answer
88 views

Is the $SHELL environment variable only for interactive shells?

I see two possible uses for the SHELL environment variable: It can be used to specify the interactive shell the user wants to use, and/or it can be used by processes to execute other commands with, ...
61
votes
3answers
11k 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?
0
votes
2answers
103 views

POSIX regular expression match on first occurrence of string

I have bash script I only want to support long options ("--option"). An --option can optionally have one or more arguments. All words (anything delimited by whitespace) up to but not including the ...
3
votes
2answers
79 views

Is a sub-shell the same thing as a child-shell

There are this two names: a subshell and a child-shell. Yes, a child process will be started by any of this: sh -c 'echo "Hello"' ( echo "hello" ) echo "$(echo "hello") echo "hello" | cat Are all ...
12
votes
4answers
10k 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 ...
0
votes
0answers
27 views

`getaddrinfo`: what specifies its data source in the POSIX standard?

I wanted to check getaddrinfo is expected to use Unbound when it's installed. Unless I overlooked something in this specification, it does not refer to any data sources it is required to check: ex. no ...
-4
votes
1answer
74 views

Simple bash script to print prime numbers from 1 to 1000 [closed]

How can I make a POSIX script that will print all the prime numbers from 1 to 1000? Lots of thanks
1
vote
2answers
26 views

Should the operands to a utility always appear after all the options to the utility?

POSIX says utility_name[-a][-b][-c option_argument] [-d|-e][-f[option_argument]][operand...] ... The arguments following the last options and option-arguments are named "operands". ...
4
votes
3answers
104 views

Force POSIX mode

Brace Expansion, eg {a,b,c} is not defined by POSIX. I would like to run my shell in POSIX mode. With Debian this is simple enough: $ bash -c 'echo {a,b,c}' a b c $ sh -c 'echo {a,b,c}' {a,b,c} ...
3
votes
7answers
401 views

Check if shell variable contains an absolute path

I want to check if a shell variable contains an absolute path. I don't care if the path exists or not—if it doesn't I'm going to create it—but I do want to ensure that I'm dealing with an absolute ...
1
vote
0answers
22 views

Why are there no LSM hooks in the POSIX IPC APIs?

As I understand it, the Linux Security Module (LSM) framework has many hooks which are callbacks for security modules to register functions performing additional security checks before ...
0
votes
2answers
1k views

How to install php7 modules in archlinux?

I have the following php version installed: PHP 7.0.2 (cli) (built: Jan 6 2016 11:50:59) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies ...
2
votes
2answers
330 views

uname -n vs hostname

What is the difference between uname -n and hostname? Are there any real differences in what they return? Are there any differences in availability on different OSes? Is one of them included in POSIX ...
8
votes
2answers
65 views

What does [[.ch.]] mean in a regex?

Alternate title: What is a "collating sequence" or "collating element" in a POSIX-compliant regex? I found the exact technical definition in Section 9.3.5 of the POSIX specs, as item #4 in the list, ...
37
votes
5answers
6k 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 ...