New answers tagged

1

It's what it says on the tin: “Maximum length of command we could actually use” is the maximum possible command line length, given the limit on the platform where xargs is running and the space taken up by the environment. This value only depends on the platform configuration and the environment. “Size of command buffer we are actually using” is the size ...


-3

This is a well known pitfall in the definition of the tar command line syntax. The problem can be avoided by using my star instead. star uses a different much less error sensible CLI definition when you call it under the name star and it is still much safer than the traditional tar implementation as it will not overwrite plain files when called as tar.


0

Explanation: The f in cvf is a shortcut for the -f option, which expects the name of the target file to tar to as next parameter. The outcome of switching the order of parameters has already been described by @AndrewHenle and @StephenKitt.


4

You asked tar to archive the files file2 and total.tar in the archive called file1, which it attempted to do. Unfortunately that means that file1 was overwritten, all you can get from it now is file2: tar tvf file1 (don't add a z in there, you didn't specify it when creating the archive). The only way you'll recover file1 is from backups.


3

Since the documentation is fairly explicit, I would simply file a bug report. Comparing with BWK (one-true-awk or original-awk), it behaves as the documentation implies. If gawk's developer had some other reference implementation in mind for this detail, it should be documented. Testing gawk's -c (compatibility mode), it treats RS as described in the ...


2

Yes, cd - is POSIX mandated: and so is tilda expansion (all it takes is a little of web searching ;-)) Your cd builtin (technically not a "program") will need to do some option parsing too if it wants to be POSIX compliant. As for globbing vs shell expansion, the way I understand it, globbing is a particular case of shell expansion that involves a ...


6

Tilde expansion is part of shell command processing, not part of cd. cd sees the already-expanded path as its argument. POSIX requires cd - to be equivalent to cd "$OLDPWD" && pwd. OLDPWD must be set by cd if PWD exists at the time of running the command.


2

Tilde expansion seems to be standardized (cf. IEEE Std 1003.1, 2004), but is part of the shell expansion, not of cd. cd - must also be supported (cf. IEEE Std 1003.1,2005).


2

Unfortunately, to manipulate the content of a binary file, dd is pretty much the only tool in POSIX. Although most modern implementations of text processing tools (cat, sed, awk, …) can manipulate binary files, this is not required by POSIX: some older implementations do choke on null bytes, input not terminated by a newline, or invalid byte sequences in the ...


0

Part of the point of using dd at all is that the user gets to pick the block size it uses. If dd fails for too large block sizes, IMO it's the user's responsibility to try smaller block sizes. I could ask for a TB from dd in one block, but that doesn't mean I'll get it. If you want an exact number of bytes, this will be horrendously slow, but should work: ...


0

/dev/{stdout,stdin,stderr} work in Bash on these platforms: Linux debian-ppc 3.16.0-4-powerpc #1 Debian 3.16.7-ckt25-1 (2016-03-06) ppc GNU/Linux HP-UX hpux-ia6 B.11.31 U ia64 0107668277 unlimited-user license AIX aix7 1 7 000ACFDE4C00 FreeBSD freebsd.polarhome.com 10.0-RELEASE-p7 FreeBSD 10.0-RELEASE-p7 #0: Tue Jul 8 06:37:44 UTC 2014 ...


0

One issue with /dev/stdout and friends is that you may not have permission to write to them in certain circumstances. For example, I've encountered this when invoking scripts from Nix, and I imagine similar tools which run scripts in jails/sandboxes/containers/VMs/etc. may encounter similar issues. Using syntax like 1>&2 worked in these cases and, ...


0

You can use ShellCheck (GitHub) as a linter for your shell scripts. There is also an online version. To detect POSIX compatibility issues (e.g. SC2039), the shebang line of your shell script should be #!/bin/sh. You can also pass --shell=sh to shellcheck. Example (test.sh): #!/bin/sh if [[ $HOSTNAME == test ]]; then echo fail &> foo fi Result ...


1

Here is a way that should work with all Bourne syntax / POSIX shells and uses only builtins : if (set -f ; IFS=$'\n'; set -- x${myvar}x ; [ $# = 1 ]) ; then echo "Your variable has only one line, proceeding" else echo "Error condition, variable must have exactly one line" fi If your shell doesn't support IFS=$'\n' (like dash 0.5.7), you can use ...


3

There are several options (bash first, POSIX is below). The code inside each function could be easily used outside. #!/bin/bash nl=$'\n' aregex (){ [[ $a =~ $nl ]]; } apattern (){ [[ $a == *$nl* ]]; } acut (){ [[ $a != "${a%%"$nl"*}" ]]; } areplace (){ [[ $a != "${a//"$nl"/}" ]]; } acase (){ case $a in (*$nl*) true;; (*) ...


5

The following snippets works in bash (with and without the -posix option): #!/bin/bash #!/bin/bash -posix version_1 () { [[ "$myvar" = *$'\n'* ]]; } version_2 () { local newlines="${myvar//[^$'\n']/}" [[ "${#newlines}" -eq 1 ]] } for test in version_1 version_2; do if $test; then echo many lines; else echo one line; fi done


7

The POSIX way: NL=' ' case $myvar in *"$NL"*) echo more than one line ;; *) echo one line ;; esac This also works in pre-POSIX Bourne-like shells, too.


2

My approach would be this one: Execute command as background process 1 Execute "watchdog timer" as background process 2 Set up a handler to trap a termination signal in the parent shell Wait for both processes to complete. The process that terminates first, sends the termination signal to the parent. The parent's trap handler kills both background ...


2

You can use -path to match a given depth and prune there. Eg find . -path '*/*/*' -prune -o -type d -print would be maxdepth 1, as * matches the ., */* matches ./dir1, and */*/* matches ./dir1/dir2 which is pruned. If you use an absolute starting directory you need to add a leading / to the -path too.


0

Here is an example: split("delta alfa charlie bravo", ech) for (fox in ech) { gol = ech[fox] hot = fox - 1 while (hot && ech[hot] > gol) { ech[hot+1] = ech[hot] hot-- } ech[hot+1] = gol } http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#AWK


1

See wikipedia. POSIX is a specification (written on papers, or in many web pages, notably OpenGroup). Unix is a family of operating systems, originally started at Bell Labs (by Thompson, Ritchie, Kernighan et al..). Later, Unix inspired POSIX. Read the history of Unix. Linux is a free software kernel under GPLv2 license started by Linus Torvarlds (mixed ...


3

If you have a stop condition on your tshark you can simply pipe the output into |sort -u. Alternatively, pipe continuous output into awk '{if(!seen[$0]++)print}' You may need to have tshark not buffer its stdout: try prefixing the tshark with stdbuf -o L.



Top 50 recent answers are included