我试图使用xargs传递参数echo:
[usr@linux scripts]$ echo {0..4} | xargs -n 1 echo
0
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
被-n 1保险人认为xargs通行证1的时间到了echo.
然后我想两次使用这个武器,但结果不是我想要的:
[usr@linux scripts]$ echo {0..4} | xargs -I@ -n 1 echo @,@
0 1 2 3 4,0 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
-n 1当我添加时,似乎禁用了-I@,这是我想要的结果:
0,0
1,1
2,2
3,3
4,4
Run Code Online (Sandbox Code Playgroud)
我怎么能实现这一目标?
--------供应------------------我使用了@ 123推荐的方法,但还有另外一个问题:
test.sh:
#!/bin/bash
a[0]=1
a[1]=2
echo "a[0] and a[1] : "${a[0]}, ${a[1]}
echo -n {0..1} | xargs -I …Run Code Online (Sandbox Code Playgroud) 在我的项目中,MyClass.h文件中有几行
class MyClass{
public:
....
#ifndef __MAKECINT__
std::vector<Status_e(MyClass::*)(TupleInfo & info)> m_processObjects; //!
#endif
....
}
//The Status_e is an enum type
//The TupleInfo is a struct
Run Code Online (Sandbox Code Playgroud)
我*在上面的代码片段中无法理解这个用法.在MyClass.cxx文件中,m_processObjects用作:
for (unsigned int f = 0; f < m_processObjects.size(); ++f) {
status = (this->*m_processObjects[f])( m_tuples[i] );
if ( status == FAILURE ) {
return EL::StatusCode::FAILURE;
}
....
}
....
Run Code Online (Sandbox Code Playgroud)
我从来没有听说过这样的用法this->*blabla,但这段代码片段有效.那意味着什么?
我想按照之前的最后一个数字排序space.这是一个简化的例子:
c3_abl_eerf_14 sasw
a.bla_haha_2 dnkww
s.hey_3 ddd
Run Code Online (Sandbox Code Playgroud)
这就是我想要的结果:
a.bla_haha_2 dnkww
s.hey_3 ddd
c3_abl_eerf_14 sasw
Run Code Online (Sandbox Code Playgroud)
我不知道怎么做,也许是通过命令sort?并且,有时我使用了sort命令,它可能错误地处理了不到2的14,我不希望这种情况发生.
我有一个非常简单的 shell 脚本名称test.sh:
[mylinux ~]$ cat test.sh
echo "a"
echo "${0}"
Run Code Online (Sandbox Code Playgroud)
然而,当我source和sh它时,结果却截然不同:
[mylinux ~]$ sh test.sh
a
test.sh
[mylinux ~]$ source test.sh
array : x, y
0,x
1,x
Run Code Online (Sandbox Code Playgroud)
我无法理解 的结果source test.sh,并且在更改 的名称后test.sh,结果也发生了变化:
[mylinux ~]$ mv test.sh a.sh
[mylinux ~]$ source a.sh
a
-bash
Run Code Online (Sandbox Code Playgroud)
我该如何理解这种现象呢?
我发现了真正的问题,那就是,即使他们没有这样的文件test.sh,我什至可以执行source test.sh以获得结果:
[mylinux ~]$ rm test.sh
[mylinux ~]$ source test.sh
array : x, y
0,x
1,x
Run Code Online (Sandbox Code Playgroud)
这对我来说很奇怪......
我要做的是在 python 函数中创建多个输出流,并将它们称为1, 2, 3.....: In test.py:
def main():
...
print >>fd1, 'words1'
print >>fd2, 'words2'
print >>fd3, 'words3'
...
Run Code Online (Sandbox Code Playgroud)
使用时重定向它:
python test.py 1>1.txt 2>2.txt 3>3.txt
Run Code Online (Sandbox Code Playgroud)
这些文件的内容:
1.txt -> words1
2.txt -> words2
3.txt -> words3
Run Code Online (Sandbox Code Playgroud)
问题是,如何创建那些fd1, fd2, fd3?
添加:
我用过这个:
outfiles = {}
for _ in range(3):
fd = os.dup(1)
outfiles[fd] = os.fdopen(fd, 'w')
def main():
for no in outfiles:
print >>outfiles[no], "foo"
print >>outfiles[no], outfiles[no].fileno()
Run Code Online (Sandbox Code Playgroud)
但结果取决于我如何执行此代码:
例如1:
python test.py …Run Code Online (Sandbox Code Playgroud) 我有像 c++ std::map 对象
std::map<std::string, int> data = {{"a",1},{"b",2}};
Run Code Online (Sandbox Code Playgroud)
我有一个字符串表达式由这个映射中的键组成:
"(a%2)+2*((b-2)%2)"
Run Code Online (Sandbox Code Playgroud)
我要做的就是计算这个表达式的值,返回类型应该是int. 有没有办法做到这一点?也许这个boost包可能会有所帮助。