A=Book,Pen,Pencil...n
B=Cat,Rat,Bat.....m
코드는 다음과 같습니다::
Type=()
TEST=`echo $path`
echo $TEST
산출::
n/m
예외 출력::
Book/Cat/Book/Rat/Book/Bat/..../Book/m/Pen/Cat/Pen/Rat/Pen/Bat/...../Pen/m/Pencil/Cat/Pencil/Rat/Pencil/Bat/..../Pencil/m/......./n/Cat/n/Rat/n/Bat/...../n/m
답변1
질문의 요구 사항을 변경한 후다시...
당신 은 bash
사용할 수 있습니다버팀대 확장:
$ printf '%s' {Book/,Pen/,Pencil/,n/}{Cat/,Rat/,Bat/,m/}
Book/Cat/Book/Rat/Book/Bat/Book/m/Pen/Cat/Pen/Rat/Pen/Bat/Pen/m/Pencil/Cat/Pencil/Rat/Pencil/Bat/Pencil/m/n/Cat/n/Rat/n/Bat/n/m/
출력은 개행 문자로 끝나지 않습니다.
및 path
에서 두 개의 쉼표로 구분된 문자열을 생성 하려면 다음을 수행합니다.$A
$B
#!/bin/bash
A="Book,Pen,Pencil,n"
B="Cat,Rat,Bat,m"
oldIFS=$IFS
IFS=,
for i in $A; do
for j in $B; do
path+="$i/$j/"
done
done
IFS=$oldIFS
printf '%s\n' "$path"
산출:
$ ./script.sh
Book/Cat/Book/Rat/Book/Bat/Book/m/Pen/Cat/Pen/Rat/Pen/Bat/Pen/m/Pencil/Cat/Pencil/Rat/Pencil/Bat/Pencil/m/n/Cat/n/Rat/n/Bat/n/m/
답변2
이 시도,
#complete_robotpath=() ### not used in script ... so commented
IFS=','
A=Basic-Call,Call-Hold ## In shell, we dont prefix with $ while declaring variable and should not have space in value.
B=VoLTE-VoLTE,VoLTE-3G
read -ra ADDR1 <<< "$A" ## In shell, we should pass value of a variable by prefixing with $
read -ra ADDR2 <<< "$B" IFS=',' ## In shell, we should pass value of a variable by prefixing with $
for i in "${ADDR1[@]}";
do
for j in "${ADDR2[@]}";
do
robot_path+=`echo $i/$j/` ## "+=" to concatinate string and sufix by / as expected result
done
done
pybot_exec_cmd=`echo $robot_path`
echo $pybot_exec_cmd
산출:
Basic-Call/VoLTE-VoLTE/Basic-Call/VoLTE-3G/Call-Hold/VoLTE-VoLTE/Call-Hold/VoLTE-3G/