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
27 views

Is there a minimal POSIX shell for OS X?

Is there a minimal POSIX shell implementation for OS X? I like to write fairly portable shell scripts and want to catch as many incompatibilities or bashisms up front as I can. I'm not intending to ...
0
votes
1answer
28 views

Checking that $((a * b)) evaluates in my own shell [closed]

POSIX seems to define that a shell should be able to evaluate like a calculator the expression $(( a * b)) where * is a binary operator +, - or *. I programmed such a calculator for my own shell and ...
1
vote
2answers
40 views

How to benchmark different shells [closed]

I want to know if shell 1 is better for a job than shell 2 with a test that I handle maybe with shell 3 for example ksh, dash, bash or zsh. I use a test script that builds my projects, starts it,feed ...
3
votes
3answers
106 views

Reverse sequence of a file with POSIX tools?

Is there any clean, clear-cut POSIX equivalent to tac? Readability as well as succinctness should both be considered.
2
votes
1answer
51 views

Differences between declared, defined, and set

In shell, what are the differences between a variable that is declared, defined and set? Does "declared" mean the identifier of the variable exists, but the storage and value of the variable do ...
0
votes
1answer
33 views

Can all of fork(), exec() and system() be wrong? [closed]

I understand why it could be less than best practice if I write C code that executes shell commands by calling system() and that it's better to use exec and fork but then a very experienced C ...
0
votes
0answers
9 views

Is editline tab completion supposed to work? [migrated]

Is there a way for libedit (editline) to do tab completion if I use editline for a small shell? It seems that rl_parse_and_bind is not available if I include histedit.h - why doesn't it work? int ...
0
votes
1answer
59 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
54 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
64 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
199 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
56 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 ...
3
votes
4answers
145 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" ...
3
votes
1answer
56 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
57 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?
12
votes
1answer
160 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 ...
-1
votes
1answer
29 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
33 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 ...
1
vote
2answers
51 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
49 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 ...
1
vote
3answers
287 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
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 ...
0
votes
3answers
78 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 ...
0
votes
2answers
35 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 ...
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 ...
7
votes
1answer
580 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
54 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
55 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 ...
1
vote
2answers
119 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
53 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 ...
1
vote
2answers
83 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 ...
16
votes
4answers
771 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 [ ...
4
votes
1answer
92 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, ...
0
votes
2answers
109 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 ...
8
votes
2answers
118 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 ...
3
votes
2answers
84 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 ...
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
86 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
27 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
119 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} ...
1
vote
0answers
24 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 ...
3
votes
7answers
446 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
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 ...
3
votes
2answers
45 views

Parameter expansion on multiple variables

Parameter expansion on a single variable works as expected. But how to expand parameters that comprise several variables? Example: #!/bin/sh foo=/lorem/ipsum; bar=dolor/sit tmp="$foo/$bar" printf ...
8
votes
2answers
67 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, ...
2
votes
1answer
99 views

Why POSIX left `$(expression)` in awk unspecified?

Answering this question, I found that in: echo 1 2 | awk '{print $(expression)}' the return value of expression is unspecified. It can lead to confusion, as if expression is an uninitialized ...
3
votes
1answer
61 views

`EINTR`: is there a rationale behind it?

Small talk as background EINTR is the error which so-called interruptible system calls may return. If a signal occurs while a system call is running, that signal is not ignored and a signal handler ...