system : Centos 6.7 Lasted
Shell : bash
python : 2.6.6
It really bothers me! example below:
5 files:
a1111 a2222 b1111 b2222 t.py
t.py content:
import sys
if __name__ == '__main__':
a1 = sys.argv[1]
print 'id(a1)=%s, len(a1)=%s, str(a1)=%s, type(a1)=%s' % (id(a1), len(a1), str(a1), type(a1))
do it like this:
ls | xargs -I{} echo $(python t.py '{}')
output:
id(a1)=139821454683184, len(a1)=2, str(a1)=a1111, type(a1)=<type 'str'>
id(a1)=139821454683184, len(a1)=2, str(a1)=a2222, type(a1)=<type 'str'>
id(a1)=139821454683184, len(a1)=2, str(a1)=b1111, type(a1)=<type 'str'>
id(a1)=139821454683184, len(a1)=2, str(a1)=b2222, type(a1)=<type 'str'>
id(a1)=139821454683184, len(a1)=2, str(a1)=t.py, type(a1)=<type 'str'>
my question is why len (a1) = 2, but str (a1) = a1111 ?, the line length is obviously not 2 ,
no echo is OK, but that's not my question. I have the xargs -p option to print cmd
ls | xargs -I{} python t.py '{}'