我有以下内容test.cppC++ 程序
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main()
{
float a,b,c;
cout<<"Give 1st number";
cin>>a;
cout<<"Give 2nd number:";
cin>>b;
c=a+b;
cout<<"\n"<<a<<"+"<<b<<"="<<c<<endl;
return 0;
}
我想创建一个外壳脚本它给出了输入变量。
我知道如何传递一个变量,我想知道是否有一种方法传递2个变量...
像下面这样test.sh不工作的文件
#!/bin/bash
g++ test.cpp -o testexe
chmod +x testexe
a=1
b=2
./testexe <<< $a $b
不仅兼容 bash,还兼容/bin/sh
-- 在避免管道开销的同时 -- 使用定界符:
./testexe <<EOF
$a
$b
EOF
如果您不关心管道开销(并且仍然维护/bin/sh
兼容性,任何答案都使用<<<
lacks):
printf '%s\n' "$a" "$b" | ./testexe
如果你不关心/bin/sh
兼容性:
./testexe <<<"$a"$'\n'"$b"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)