Bash脚本和命令行参数

时间:2021-06-29 01:47:33

So I have a file that is called "run_correlation_study.pbs" and "correlation_study.pbs". In correlation_study.pbs, I run a bash script that uses portable batch software(pbs) and assign 3 command line arguments that will be used in my actual program. In run_correlation_study.pbs, I loop through the command line arguments that are used in correlation_study.pbs so that I can split up my program into multiple jobs for a computing cluster. However, I have been getting errors with my run_correlation_study.pbs file when I try to run it (I turn it into an executable file before running it). I have posted both file below, run_correlation_study.pbs is listed first and correlation_study.pbs is listed second. I can provide the part of my program where the command line arguments are used but I do not think the problem is caused in there. Also, the error/text that shows up when I try to run my program is listed last.

所以我有一个名为“run_correlation_study.pbs”和“correlation_study.pbs”的文件。在correlation_study.pbs中,我运行一个使用便携式批处理软件(pbs)的bash脚本,并分配3个命令行参数,这些参数将在我的实际程序中使用。在run_correlation_study.pbs中,我遍历在correlation_study.pbs中使用的命令行参数,以便我可以将我的程序拆分为计算集群的多个作业。但是,当我尝试运行它时,我的run_correlation_study.pbs文件出现错误(我在运行之前将其转换为可执行文件)。我在下面发布了两个文件,首先列出run_correlation_study.pbs,然后列出correlation_study.pbs。我可以提供我的程序中使用命令行参数的部分,但我不认为问题是由那里引起的。此外,最后列出了我尝试运行程序时显示的错误/文本。

Run_correlation_study.pbs:

    for ((ARC_LENGTH = 0; ARC_LENGTH <= 35; ARC_LENGTH++)); do
       qsub -v ARC_LENGTH_ARG=$ARC_LENGTH/10, RANDOM_NUM_ARG=$ARC_LENGTH correlation_study.pbs
    done

Correlation_study.pbs:

    #PBS -l walltime=24:00:00
    #PBS -l nodes=1:ppn=1
    #PBS -N Correlation_study_data
    #PBS -j oe
    #PBS -m abe

    #COMMANDS TO RUN
    cd /home/kovacevich.9/correlation_study/corrstudies
    ./correlation_study.x ${ARC_LENGTH_ARG} ${RANDOM_NUM_ARG}

Error/text:

   usage: qsub [-a date_time] [-A account_string] [-b secs]
   [-c [ none | { enabled | periodic | shutdown |
   depth=<int> | dir=<path> | interval=<minutes>}... ]
   [-C directive_prefix] [-d path] [-D path]
   [-e path] [-h] [-I] [-j oe] [-k {oe}] [-l resource_list] [-m n 
   {abe}]
   [-M user_list] [-N jobname] [-o path] [-p priority] [-P proxy_user] 
   [-q queue] 
   [-r y|n] [-S path] [-t number_to_submit] [-T type]  [-u user_list] 
   [-w] path
   [-W additional_attributes] [-v variable_list] [-V ] [-x] [-X] [-z] 
   [script]

Portion of program:

方案部分:

    if(argc == 3)
    {
       double test_arc_length = atof(argv[1]);
       unsigned long int seed = atoi(argv[2]);

1 个解决方案

#1


0  

To do floating point arithmetic from bash, you need to call out to an external program. You could do one of:

要从bash执行浮点运算,需要调用外部程序。你可以做一个:

qsub -v "ARC_LENGTH_ARG=$(bc -l <<<"$ARC_LENGTH/10"),..."
qsub -v "ARC_LENGTH_ARG=$(awk -v "a=$ARC_LENGTH" 'BEGIN {print a/10}'),..."

Using command substitution syntax $(cmd ...) within a double quoted string.

在双引号字符串中使用命令替换语法$(cmd ...)。

#1


0  

To do floating point arithmetic from bash, you need to call out to an external program. You could do one of:

要从bash执行浮点运算,需要调用外部程序。你可以做一个:

qsub -v "ARC_LENGTH_ARG=$(bc -l <<<"$ARC_LENGTH/10"),..."
qsub -v "ARC_LENGTH_ARG=$(awk -v "a=$ARC_LENGTH" 'BEGIN {print a/10}'),..."

Using command substitution syntax $(cmd ...) within a double quoted string.

在双引号字符串中使用命令替换语法$(cmd ...)。