首页 > 解决方案 > Bash argument input changes?

问题描述

I have a bash script that takes in arguments from the command line:

path2self=$(dirname "$(readlink -f "$0")")

path2Intersection=$1
normal=$2
matched=$(echo "$3" | awk '{print tolower($0)}')
csv=$4
f1=$5
f2=$6
f3=$7
f4=$8
r1=$9
path2database=$10
b1=$11
b2=$(echo "$12" | awk '{print tolower($0)}')
b3=$13

echo $path2database
echo $b1

However, if I run it with this: sh /path/to/script.sh /path/to/Intersection /path/to/normal true /path/to/csv.csv 4 10 0.05 0.01 mut /path/to/databases /path/to/b1 true /path/to/b3 I get this output:

/path/to/Intersection0
/path/to/Intersection1

I don't know why the argument is passing what I send to it through the command line isn't the same. Does anyone know what is going on?

标签: bash

解决方案


$10最终将作为 和 的值的串联,$1'0'可以在结果中完美地观察到。$11其他所有超过一位数的情况也是如此。

只需在标识符周围添加花括号即可正确扩展变量 =>${10}


推荐阅读