Skip to content

Instantly share code, notes, and snippets.

@TheBigFish
Forked from UniIsland/xargs_with_function.sh
Created August 3, 2021 08:47
Show Gist options
  • Select an option

  • Save TheBigFish/f5538202e02e51f5f3b6f972c29ce9c9 to your computer and use it in GitHub Desktop.

Select an option

Save TheBigFish/f5538202e02e51f5f3b6f972c29ce9c9 to your computer and use it in GitHub Desktop.
use xargs with bash function
#!/bin/bash
parse_and_echo() {
echo "\$1:$1 \$2:$2 \$3:$3 \$4:$4"
echo newline
}
export -f parse_and_echo
# `_' is placeholder for $0
cat ./xargs_with_function.txt | xargs -n 4 bash -c 'parse_and_echo $@' _
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment