xargs take string as single argument?
Hi, does anyone know if it's possible for xargs to take it's stdin and create 1 single parameter for it.
Example I want this python script's first argument to say 'hello world' like this: Code:
$ python -c 'import sys;print sys.argv[1]' 'hello world' Code:
$ echo 'hello world' | xargs python -c 'import sys;print sys.argv[1]' |
Hello,
Would one of the following work? Code:
echo "\"hello world\"" | xargs python -c 'import sys;print sys.argv[2]' Josh |
Both of those work, but I'm getting my input not from the echo command and the input varies, so quoting is not an option.
The input will be something like: Code:
$ cat emailmessage | xargs python -c 'import sys;print sys.argv[1]' |
What you could do is create a bash script to cat whatever file you need to a single variable, and then try to pass the variable over to the xargs python part. I'm not on linux right now, so I can't test this and mess around with it for you.
|
xargs can use NUL as an argument separator:
Code:
{ echo 'hello world'; echo -ne '\0' } | xargs -0 python -c 'import sys;print sys.argv[1]' |
Quote:
Thanks guys. |
alternative
Hi,
just another alternative: Code:
echo 'hello world' | xargs -I{} python -c 'import sys;print sys.argv[1]' '{}' |
Use GNU Parallel:
Code:
$ echo 'hello world' | parallel python -c 'import sys;print sys.argv[1]' |
All times are GMT -5. The time now is 12:12 PM. |