Я пытаюсь создать вывод как 12DEC2013bhav.csv.zip
в сценарии ниже.
Но это дает мне что-то как 12DEC.csv.zip
вместо этого:
for (( i = 2013; i <= 2014; i++ ))
do
for m in JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
do
for (( d = 1; d <= 31; d++))
do
echo "$d$m$ibhav.csv.zip"
done
done
done
Как я исправляю его?
Проблема состоит в том, что Вы пытаетесь сослаться на названную переменную $ibhav
(нет $i
).
Переменные могут быть больше чем одним символом, и в Вашем примере, оболочка не имеет никакого способа сказать, имели ли Вы в виду $i
или $ibhav
(или $ibha
или $ibh
или $ib
).
Фиксация должна заключить в скобки Ваши имена переменной:
echo "${d}${m}${i}bhav.csv.zip"
так, чтобы это было однозначно, на какую переменную Вы ссылаетесь.
От man bash
:
Parameter Expansion
The `$' character introduces parameter expansion, command substitution, or
arithmetic expansion. The parameter name or symbol to be expanded may be
enclosed in braces, which are optional but serve to protect the variable
to be expanded from characters immediately following it which could be
interpreted as part of the name.
When braces are used, the matching ending brace is the first `}' not
escaped by a backslash or within a quoted string, and not within an embed‐
ded arithmetic expansion, command substitution, or parameter expansion.
${parameter}
The value of parameter is substituted. The braces are required
when parameter is a positional parameter with more than one digit,
or when parameter is followed by a character which is not to be
interpreted as part of its name. The parameter is a shell parame‐
ter as described above PARAMETERS) or an array reference (Arrays).