#include <iostream>
using namespace std;
int main(void){
int number = 0;
cout << "Please enter a number: ";
cin >> number ;
cout << "the number you enter is " << number << endl;
return 0;}
这是我的程序,它接受一个参数并将其打印出来。
#! /bin/bash
number=1
echo "1" | ./a.out #>> result.txt
这是我的 bash 脚本,它试图将参数传递给程序。
1
Please enter a number: the number you enter is 1
这是结果.txt。我希望它更像这样:
Please enter a number: 1
the number you enter is 1
我应该如何修复它,以便脚本更像人类一样传递参数。
并且 bash 是一种非常好的脚本语言来完成这种工作还是有其他更好的脚本语言。(谷歌说 tcl 对于这种交互式程序来说比 bash 更好?)