Stack Exchange Network

Stack Exchange network consists of 175 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 [posix]

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

4
votes
1answer
51 views

Does POSIX make not support globs in prerequisites?

I was reading the POSIX 7 Make definition, and I've noticed that prerequisites are almost always described as “files”: The make utility examines time relationships and shall update those derived ...
1
vote
1answer
42 views

Confused about determining if a shell script is running interactively

I only want to determine from my POSIX shell script, if it is running interactively, but for some reason, the following function: running_interactively() { printf '%s' ${-} | grep -F i > /dev/...
28
votes
11answers
6k views

Why doesn't shell automatically fix “useless use of cat”? [closed]

Many people use oneliners and scripts containing code along the lines cat "$MYFILE" | command1 | command2 > "$OUTPUT" The first cat is often called "useless use of cat" because technically it ...
-1
votes
1answer
41 views

What command is my alias running? [duplicate]

In this question it is recommended repeatedly that to figure out where an executable is located, one should run command -v file. I've tried running command -v ls on a few different systems now and I ...
3
votes
2answers
207 views

Reshaping json / reparing json inside shell script (remove trailing comma)

I've googled around a lot for this and it seems there is no precursor to this need. I need to edit an applications preference file programatically : as part of a shell script. and the prefs are ...
1
vote
2answers
148 views

How to tell without knowing the mount point that a device UUID is mounted?

System: Linux Mint 19.1 Cinnamon 64-bit, based on Ubuntu 18.04 LTS. I would like to know if it is possible to get the following information: Is this UUID (of a block device) mounted or not? (without ...
1
vote
1answer
44 views

Source of /etc/protocols and /etc/services?

Those files are databases which contain IP protocol number, alias and service mappings. As a user I don't usually interact with those in any direct way, but the need to create special Linux/GNU ...
2
votes
1answer
36 views

Is it safe to close a directory stream (DIR *) in both the parent and child process?

This page describes the guaranteed behavior of the functions readdir and readdir_r and contains the following sentence: After a call to fork(), either the parent or child (but not both) may ...
3
votes
0answers
57 views

How little work could `/usr/bin/cd` or `/usr/bin/wait` do and still be conforming?

Can the executables with the same names as shell builtins get away with doing a lot less "work" than the shell builtins do? For instance, could the fg executable just exit abnormally immediately? ...
6
votes
2answers
245 views

Is there a POSIX way to shutdown a UNIX machine?

I am searching for a POSIX command to shutdown a machine. Is there a POSIX acceptable way to do this? The commands I use to do this are not POSIX compatible (e.g., shutdown, reboot, halt or ...
1
vote
1answer
42 views

How to test whether my tail is posixly correct?

I'm having problems with a vim interface for the theorem prover HOL: https://github.com/HOL-Theorem-Prover/HOL/tree/master/tools/vim I run it on MobaXterm, a cygwin-based system, and vim is freezing ...
1
vote
1answer
35 views

understanding backslash in POSIX standard

I've seen interesting video about POSIX standard on youtube. It was part of lecture, asking if anyone knows the result of echo \\\\\\ in bash, and sh(POSIX standard?) sh-3.2$ echo \\\\\\ \\ bash$...
1
vote
1answer
38 views

shellcheck: “In POSIX sh, ulimit -H is not supported”

I am using shellcheck to fix warnings in a sh script. The script checks for the hard fd limit with: ulimit -H -n It sets the soft fd limit with: ulimit -n "$MAX_FD" This generates the shellcheck ...
0
votes
1answer
67 views

Wildcards/Globbing: Are character ranges problematic?

In The Linux Command Line William Shotts claims that character ranges can be problematic. See the relevant excerpt below, emphasis is mine. Character Ranges If you are coming from another Unix-...
1
vote
1answer
27 views

Difference between file capability and process capability

I am trying to understand POSIX Capabilities. Sometimes, when reading the documentation they refer to file capabilities and sometimes to process capabilities. What is the difference between file and ...
1
vote
4answers
58 views

How can I feed a string to awk for the purpose of mathematical calculation?

#!/bin/sh -- expression_to_evaluate='12 + 3' printf '%s\n' "Arithemtic Expansion: $(( $expression_to_evaluate ))" printf '%s' 'bc: ' printf '%s\n' "$expression_to_evaluate" | bc printf '%s' 'awk: '...
1
vote
1answer
36 views

Expose mount from LXC to host

I am working with a proprietary POSIX client to mount a network directory. The packages provided by the vendor are horrible (e.g., post-install that does ln -sf /usr/bin/fusermount?!), so I'm trying ...
3
votes
0answers
30 views

Portable, race-free equivalent of mv -T DIR1 DIR2?

It seems mv -T is a GNU extension to mv. Is there a robust way (race-free, portable, and otherwise without "gotchas") to do the equivalent of mv -T dir1 dir2? To be clear: I DO NOT want this to ...
18
votes
2answers
1k views

Why does POSIX require certain shell built-ins to have an external implementation?

From this question about whether printf is a built-in for yash, comes this answer that quotes the POSIX standard. The answer points out that the POSIX search sequence is to find an external ...
14
votes
3answers
535 views

Slightly confused about whether printf in the yash shell is a built-in command or not

The yash shell has a printf built-in, according to its manual. However, this is what I see in a yash shell with default configuration: kk@eeyore ~ $ command -v printf /usr/bin/printf kk@eeyore ~ $ ...
0
votes
0answers
25 views

Avoiding echo -e [duplicate]

I would like to store an HTTP request in a variable and then use it with OpenSSL I now have HTTP_REQUEST="HEAD / HTTP/1.1\\nHost: ${HOST_HEADER}\\nUser-Agent: check_ssl_cert/${VERSION}\\nConnection: ...
0
votes
1answer
41 views

Does POSIX guarantee certain usernames?

In the POSIX Definitions there is specific section 3.424, User Database, which defines what information should be related to each user ID. However through out the document, I couldn't find (at least ...
1
vote
1answer
87 views

What characters need to be escaped when using the printf command?

I want to clarify that I am not talking about how to escape characters on the shell level of interpretation. As far as I can tell, only two character need to be escaped: % and \ To print a literal %,...
0
votes
2answers
83 views

Is the behavior of escaping special characters inside double-quotes in mainstream POSIX-compliant shells at odds with POSIX?

Per the POSIX Shell Command Language Page: \ The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
3
votes
3answers
124 views

POSIX Shell: inside of double-quotes, are there cases where `\` fails to escape `$`, ```, `"`, `\` or `<newline>`?

Per the POSIX Shell Command Language Page: \ The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
8
votes
2answers
429 views

Explanation needed on how I can repeat a character in POSIX shell

The following answer on Stack Overflow, How can I repeat a character in bash? imposes one plausible way of POSIX-ly repeating a single character, as follows. In this example let's use the equal sign ...
17
votes
2answers
1k views

POSIX shell: does `$` lose its special meaning if it is the last character in a word?

On ash, dash and bash, when I run $ echo ab$ it returns ab$ Is this behavior specified by POSIX or is it just a common convention in POSIX-compliant shells? I couldn't find anything on the POSIX ...
1
vote
0answers
45 views

Two replacements in one go [duplicate]

How do I go about replacing one character for another and then another character for another in one line and printing the result? As an example, consider the following code: string="1 33 4 a" echo ${...
8
votes
1answer
126 views

Why was POSIX.1e withdrawn?

The proposed POSIX.1e standard defines a few things like ACLs that are widely supported. But the proposal itself was withdrawn. How come? The only reasoning I've found online is this quote from ...
17
votes
3answers
2k views

Why is the behavior of the `#!` syntax unspecified by POSIX?

From the Shell Command Language page of the POSIX specification: If the first line of a file of shell commands starts with the characters "#!", the results are unspecified. Why is the behavior of #...
-1
votes
2answers
108 views

What kind of language construct is the swung dash (tilde, ~)?

The swung dash can be used in place of the home directory. Depending on the current user it has a different value. In this sense it works like a variable. Yet it is not a variable. I can't do echo $~...
0
votes
0answers
23 views

The thread in “Thread model: posix”

When check the version of gcc $ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/...
1
vote
1answer
124 views

Unexpected split behavior

I read about Awk split behavior here: [...] the fs argument to the split function (see String Functions) shall be interpreted as extended regular expressions. These can be either ERE tokens or ...
10
votes
3answers
759 views

How to POSIX-ly count the number of lines in a string variable?

I know I can do this in Bash: wc -l <<< "${string_variable}" Basically, everything I found involved <<< Bash operator. But in POSIX shell, <<< is undefined, and I have ...
-2
votes
1answer
195 views

Migrating shell scripts from Solaris 10 to RHEL 7.5 [closed]

Source environment: $ uname -a SunOS machine1 5.10 Generic_150400-63 sun4u sparc SUNW,SPARC-Enterprise $ pwd / $ ls -l /bin/sh lrwxrwxrwx 1 root root 13 Nov 1 19:39 /bin/sh -> ../.....
5
votes
0answers
78 views

Correct treatment of quotes in parameter expansions

Using the default value of IFS, consider unset var set -- ${var:-"hello"} echo "$#" This prints 1 as the parameter expansion expands to the single string hello. unset var set -- "${var:-"hello"}" ...
1
vote
4answers
844 views

Argument list too long error with makefile

In a makefile, I have @echo "$(IGNORE_DIRS) $(CLEAN_FILES) $(CLEAN_DIRS) $(REALCLEAN_FILES)" | tr ' ' '\n' >> $@ The problem is that $(CLEAN_FILES) is quite large, so when I run make, I get ...
3
votes
1answer
55 views

String substitution: If empty replace, otherwise make empty

I was wondering if there's a shorthand for this kind of stuff. Currently I can do. var_empty=; [ -n "$var" ] || var_empty=1; #intermediary variable echo "REPL_if_var_empty_otherwise_empty=${...
2
votes
0answers
75 views

How can I make named pipes atomic or is there an alternative? [duplicate]

Reopen voters: flock() doesn't work on named pipes, this is not a dupe. I was trying to do the following with named pipes: mkfifo example.txt ( printf "456"; printf "abc"; printf "\n"; ) > ...
0
votes
1answer
58 views

calling fsync() on in-memory files

From fsync(2): fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other ...
1
vote
1answer
70 views

Using exec 1>&2 in a POSIX shell script function. Will it interfere with other io-redirects?

I am in process of writing a POSIX shell script. I have one function, which redirects (almost) all output to standard error stream like that: # print something to stderr printf "..." $var 1>&...
4
votes
1answer
356 views

zsh and POSIX equivalent of bash's `{var}>&1`

Is there an equivalent of {var}>&1 in zsh? The bash manual says: Each redirection that may be preceded by a file descriptor number may instead be preceded by a word of the form {varname}. ...
0
votes
2answers
43 views

Equivalent to GNU find -printf flag in other find implementations

Specifically, in mkinitcpio the command find -mindepth 1 -printf '%P\0' is used, what would be a way to recreate a command with identical output without the -printf flag. https://git.archlinux.org/...
3
votes
1answer
51 views

Is there a portable way to switch text case from the command line?

Is there a way, portable across POSIX operating systems and locale-aware, to switch text case from the command line--that is replacing lower case letters by upper case ones and vice versa. Using GNU ...
5
votes
1answer
292 views

POSIX find all non readable files

I am trying to find all non readable 'ACL-wise' in a subdirectory owned by another user www-data, and that on a 'FreeBSD' server. This server prevents me from using the command find . ! -readable How ...
1
vote
1answer
221 views

Can a system call with non documented `EINTR` return `EINTR`?

I am writing an small application and I want to make it as portable as possible (Linux, *BSD and possibly other UNIXes). My main issue is the management of EINTR. I read that there are some systems ...
1
vote
1answer
143 views

How to correctly store a newline character in a (POSIX) shell variable? [duplicate]

update attempt to clarify more, using an example, does the following shell commands: SHELLVARIABLE="1st line, 2nd line, 3rd line, " printf '%s' "$SHELLVARIABLE" generate this output: 1st line,<...
0
votes
0answers
22 views

How to safely preview shell's “parameter meddling”? (i.e Token recognition + wordexp)

Is there a way to preview "how the shell would interprete the user input (in terms of Token recognition, and wordexp)"? Moreover would a shell function preview () { printf '%s\n' "$*"; } be such ...
0
votes
1answer
44 views

Is a POSIX-conformant implementation required to support other than default locales?

I would like to implement a minimal POSIX-conformant make utility. However, the specification mentions that the implementation shall be affected by the following environment variables: LANG, LC_ALL, ...
3
votes
1answer
214 views

Is Linux considered XSI compliant or largely so?

From APUE The Single UNIX Specification, a superset of the POSIX.1 standard, specifies additional interfaces that extend the functionality provided by the POSIX.1 specification. POSIX.1 is ...