麻烦终端运行程序通过bash for循环

时间:2013-03-09 01:33:03

标签: bash loops terminal

#!/bin/bash

for i in {10..11}
do
    ./duffing -a 1 -b -1 -u 0.25 -w -1 -A 0.4 -t $i | ./stroboscopic > $i.data
done

$ i似乎不能在程序参数行中工作,但我得到了数据文件。这是错误

error converting i to a double for max-time:
leftover characters: i

Bad input data 
error converting i to a double for max-time:
leftover characters: i

 Bad input data 

这是我在duffing程序中解析参数的地方:

void parse_args(int argc, char **argv, state_t *state, system_t *system,
            simulation_t *simulation, int *read_initial, int *print_final)
{
    int ch;
duffing_state_t *duffing = (duffing_state_t *)system->dx_dt_state;
double dtemp;
size_t i;

while (1) {
    ch = getopt_long(argc, argv, short_options, long_options, NULL);
    if (ch == -1)
        break;
    switch(ch) {
    case 'd':
        simulation->dt = safe_strtod(optarg, "time-step");
        break;
    case 't':
        simulation->t_max = safe_strtod(optarg, "max-time");
        break;
    case 'T':
        duffing->T = safe_strtod(optarg, "transient-time");
        break;
    case 'x':
        state->x[0] = safe_strtod(optarg, "x0");
        break;
    case 'v':
        state->x[1] = safe_strtod(optarg, "v0");
        break;
    case 'm':
        system->m = safe_strtod(optarg, "mass");
        break;
    case 'a':
        duffing->a = safe_strtod(optarg, "alpha");
        break;
    case 'b':
        duffing->b = safe_strtod(optarg, "beta");
        break;
    case 'u':
        duffing->u = safe_strtod(optarg, "mu");
        break;
    case 'w':
        duffing->w = safe_strtod(optarg, "omega");
        break;
    case 'A':
        duffing->A = safe_strtod(optarg, "amplitude");
        break;
    case 'E':
        simulation->step_fn = &euler_step;
        break;
    case 'M':
        simulation->step_fn = &midpoint_step;
        break;
    case 'R':
        simulation->step_fn = &rk4_step;
        break;
    case 'i':
        *read_initial = 1;
        break;
    case 'f':
        *print_final = 1;
        break;
    case '?':
        exit(EXIT_FAILURE);
    default:
        fprintf(stderr, "?? getopt returned character code 0%o ??\n", ch);
    }
}

/* convert input from periods to seconds */
simulation->t_max *= 2*M_PI / duffing->w;
duffing->T *= 2*M_PI / duffing->w;

return;
}

我已经使用-t 10直接从终端运行程序,所以我很困惑为什么程序拒绝接受脚本的输入。

0 个答案:

没有答案