posix

Why is the following regex not working in C using regcomp

我的未来我决定 提交于 2020-01-30 11:18:32
问题 I have the following regex to match the last pair of braces in a string, .+(?={)(.+)(?=}) The example string is, abc{abc=bcd}{gef=hij} I want the contents within the last braces (gef=hij) inside the captured group. This works in a regex tester available in the web http://regexpal.com/ When I use regcomp to compile the same regex, it doesnt. Any ideas? int reti = regcomp(&regex, ".+(?={)(.+)(?=})", REG_EXTENDED); if (reti) { fprintf(stderr, "Could not compile regex\n"); exit(1); } 回答1: Anyway,

Why is the following regex not working in C using regcomp

╄→гoц情女王★ 提交于 2020-01-30 11:17:06
问题 I have the following regex to match the last pair of braces in a string, .+(?={)(.+)(?=}) The example string is, abc{abc=bcd}{gef=hij} I want the contents within the last braces (gef=hij) inside the captured group. This works in a regex tester available in the web http://regexpal.com/ When I use regcomp to compile the same regex, it doesnt. Any ideas? int reti = regcomp(&regex, ".+(?={)(.+)(?=})", REG_EXTENDED); if (reti) { fprintf(stderr, "Could not compile regex\n"); exit(1); } 回答1: Anyway,

POSIX alternative to bash read with timeout and character limit

断了今生、忘了曾经 提交于 2020-01-30 02:39:23
问题 I am writing an interactive shell script that needs to run on as many systems as possible. Is there an alternative way to implement the following that is compatible with a standard POSIX system? #! /bin/bash echo -n "Do you wish to continue? (Y/n) 5 seconds to respond... " read -n 1 -t 5 answer # accepts a single character, 5 second timeout. if [ "$answer" = "n" ] || [ "$answer" = "N" ] ; then echo -e "\nExiting..." exit fi echo -e "\nContinuing with script..." # More code The timeout on read

POSIX alternative to bash read with timeout and character limit

孤人 提交于 2020-01-30 02:39:10
问题 I am writing an interactive shell script that needs to run on as many systems as possible. Is there an alternative way to implement the following that is compatible with a standard POSIX system? #! /bin/bash echo -n "Do you wish to continue? (Y/n) 5 seconds to respond... " read -n 1 -t 5 answer # accepts a single character, 5 second timeout. if [ "$answer" = "n" ] || [ "$answer" = "N" ] ; then echo -e "\nExiting..." exit fi echo -e "\nContinuing with script..." # More code The timeout on read

Get uname release field from C# in .NET Core on Linux

▼魔方 西西 提交于 2020-01-25 09:24:17
问题 I'm trying to get the output of uname -r in C# in .NET Core 2.2 running on Ubuntu 18.04. I'm writing this with performance in mind, so have been trying to use a P/Invoke to achieve it. The uname(2) docs indicate I need to pass a struct in with the relevant sized fields. After playing with a lot of variations, I came up with: [StructLayout(LayoutKind.Sequential)] unsafe internal struct Utsname { public fixed byte sysname[65]; public fixed byte nodename[65]; public fixed byte release[65];

Is skipping/ignoring NUL bytes on process substitution standardized?

余生长醉 提交于 2020-01-25 01:48:18
问题 Executive Summary Is it standard behavior that shells skip over NUL bytes when doing process substitution? For example, executing printf '\0abc' | read value && echo $value will yield abc . The NUL value is skipped, even though the hexdump of the printf output shows it's clearly being output. My first thought was " word splitting ". However, when using an actual process substitution value=$(printf '\0abc') the results are similar and = does not perform word splitting. Long Story While

pitfalls in renaming files in bash

佐手、 提交于 2020-01-24 19:07:51
问题 I am reading a guide here http://mywiki.wooledge.org/BashFAQ/030 on this link a few examples are given I am trying to understand them one example code says # Bash # Replace all spaces with underscores for f in *\ *; do mv -- "$f" "${f// /_}"; done what I have known till now was use of a backslash for special characters like space of ~ or # etc in case of search and replace examples or in shell scripts here in above example they have used ${f// /_} forward slashes , I am not clear with this is

capability of `posix_spawn`

会有一股神秘感。 提交于 2020-01-24 12:56:51
问题 I'm writing a small program which is somewhat a server that spawns its client programs (locally, not over the network) and do interesting things between them. While my primary OS in use is Linux, I expect this to run on other OSes including Windows. There is fork and exec which does the job, but when I port the program to Windows via cygwin, I don't want that crappy fork implemented in cygwin to kick in, which actually calls CreateProcess and copies the current process's memory area to the

capability of `posix_spawn`

怎甘沉沦 提交于 2020-01-24 12:55:47
问题 I'm writing a small program which is somewhat a server that spawns its client programs (locally, not over the network) and do interesting things between them. While my primary OS in use is Linux, I expect this to run on other OSes including Windows. There is fork and exec which does the job, but when I port the program to Windows via cygwin, I don't want that crappy fork implemented in cygwin to kick in, which actually calls CreateProcess and copies the current process's memory area to the

How to conceal a segmentation fault in a bash script

北城以北 提交于 2020-01-24 09:56:26
问题 I use a program that works properly and results in desirable output at the end of its operation with no memory leak or any other specific issue, but then it issues a segmentation fault at the point it exits. I have been trying to hide this harmless but annoying error from the end user when using this program by redirecting the standard error to Null: program options >file 2>/dev/null But this doesn't work and the error shows up in the middle of the script's outputs each time I run the program