Created
May 31, 2012 01:58
-
-
Save whiteinge/2840370 to your computer and use it in GitHub Desktop.
Experimental map shell function using xargs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pull the username and password out of the xml file and into local vars | |
# Run the output through sed to escape & and _ characters for MySQL | |
# Note: the shell quoting here gets a little rough. The final command is: | |
# sed -e 's/[%_]/\&/g' | |
read dbuser dbpass <<<$(xmap \ | |
'xmlstarlet sel -t -v "//controller-config/database/@" '${XML_FILE}' \ | |
| sed -e '\''s/[%_]/\\\\&/g'\' \ | |
username password) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function xmap() { | |
# Run a shell command once for every argument passed. The first argument | |
# should be a single-quoted string appropriate to pass to sh -c. | |
# For example: | |
# % xmap 'echo @' foo bar baz | |
# echo foo | |
# echo bar | |
# echo baz | |
cmd=$1 | |
shift | |
echo -n ${@} | xargs -r -d" " -I@ sh -c "${cmd}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment