posix

How do I programmatically check if a Flatpak package is installed in a shell script?

How do I programmatically check if a Flatpak package is installed in a shell script? I’m writing a script where I want to detect whether a given Flatpak package is installed, and take a different code path depending on the answer. How can I accomplish this? Traditional measures like command -v obviously won’t work unless …

Total answers: 1

Forbids something in Posix to have an empty string as a file name?

Forbids something in Posix to have an empty string as a file name? My experience is that trying to do anything with an empty string filename results file not found (ENOENT), including a ls -ld ”, touch ” or mkdir ”. But I could try only ext4. While it looks quite logical to me, does …

Total answers: 1

POSIX Shell: `exec` with changed arg0

POSIX Shell: `exec` with changed arg0 I want to exec a program and control it’s arguments including arg0 and environment. Using C I could go for execve. Can I do this in POSIX shell? Asked By: Patrick Böker || Source According to POSIX documentation of Special Builtin Utilities, the syntax for exec is exec [command …

Total answers: 1

How do executables use POSIX to keep compatibility between different UNIX systems?

How do executables use POSIX to keep compatibility between different UNIX systems? In my understanding, POSIX only specifies a set of APIs that the OS needs to provide, but it doesn’t specify the implementation detail, specifically the assembly level compatibility. For example, on x86, you need to use a syscall to get the POSIX API: …

Total answers: 1

How to convert all newlines to "n" in POSIX sh strings

How to convert all newlines to "n" in POSIX sh strings I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "n". How can I do this in POSIX sh? Here’s the goal: $ printf ‘anbncnd’ | …

Total answers: 1

Is the following `readonly` use POSIX-ly correct?

Is the following `readonly` use POSIX-ly correct? I defined the following as read-only: readonly root_command=’sudo -s’ later used in my script as in: exec $root_command My question is, maybe I am slow or something, but I do not fully understand the POSIX man page, as for example if I can single quote or have to …

Total answers: 1

Why does the POSIX for-loop allow a `for name in ; do` (no words in list) syntax?

Why does the POSIX for-loop allow a `for name in ; do` (no words in list) syntax? I’m trying to understand the for-loop syntax in the POSIX shell grammar rules: for_clause : For name do_group | For name sequential_sep do_group | For name linebreak in sequential_sep do_group | For name linebreak in wordlist sequential_sep do_group …

Total answers: 2

Why pipe keep sudo and redirection not?

Why pipe keep sudo and redirection not? Pipe (|) and redirections (<, <<, >, >>) both using standard streams (stdin, stdout, stderr), but although only pipe can keep sudo privileges, why? Works: sudo echo "hello" | tee /root/test Doesn’t work: sudo echo "hello" > /root/test Asked By: linuxer || Source Pipe (|) and redirections (<, …

Total answers: 2

Does `return 0` equal `true` (in sourced script to shell's environment)?

Does `return 0` equal `true` (in sourced script to shell's environment)? I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as it returns true or false status to the …

Total answers: 3

Is there a difference between file permissions and mode?

Is there a difference between file permissions and mode? The terms "file permission" and "file mode" are often used interchangeably. However, some tools exclusively use one term or the other. Interestingly, the venerable chmod tool specifically refers to "file mode". Is there a technical or historical difference between them? Asked By: lonix || Source Technically …

Total answers: 2

Expand tabs in file with utf8 characters

Expand tabs in file with utf8 characters I use expand to expand tabs to spaces. For utf8 files expand doesn’t work correctly. E.g. in ćta tab is expanded to 6 spaces while in ata to 7 spaces. How do I make it work for utf8 files? Asked By: Marcin Król || Source You could use …

Total answers: 1

adapt 'exec &> >(tee -a "$LOG_FILE")' to sh

adapt 'exec &> >(tee -a "$LOG_FILE")' to sh In bash, this: exec &> >(tee -a "$LOG_FILE") Will redirect stderr & stdout to tee that allows the output to be displayed on the terminal while also logged (written to $LOG_FILE), but it uses process substitution, a feature not available in sh If I run the script …

Total answers: 2

`IFS="value" command` is a popular feature of many shells, but official documentation is hard to find. Where is it documented officially?

`IFS="value" command` is a popular feature of many shells, but official documentation is hard to find. Where is it documented officially? I constantly see IFS="value" command being referred to as a means of changing the IFS (Internal Field Separator) temporarily, only for the duration of the command provided, yet there are many situations where what …

Total answers: 1

Is `command -v program` always executable?

Is `command -v program` always executable? I am using the command -v "program" >/dev/null 2>&1 construct if I need to POSIX-ly find out if such program is installed in an if-statement. From its help page is not clear, whether it checks only for path or also for the executable bit? $ command –help command: command …

Total answers: 1

Bash posix regex optional groups

Bash posix regex optional groups Trying to match some Gentoo package naming components from strings in forms category/name-version, due to its complexity, I have come to this: if [[ "$1" =~ ^([<>]?=?)(([^/]+)/)?([^[:space:]]+)-(([[:digit:]]+)?(.([[:digit:]]+))*([a-z])?(_(alpha|beta|pre|rc|p)([[:digit:]]*))*(-(r([[:digit:]]+))?)?)?$ ]]; then # use "${BASH_REMATCH[n]}" here to capture groups contents fi It splits strings like <category/package-name-12345.25b_rc10-r7 as expected: Version specifier: < Category: category …

Total answers: 2