I have command on bash:
adb shell '/bin/sh -c "CLASSPATH=\$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -w --no-window-animation -e clearPackageData false -e annotation '$annotationsString' -e targetInstrumentation ru.hh.hhh.test/com.kaspersky.kaspresso.runner.KaspressoRunner androidx.test.orchestrator/.AndroidTestOrchestrator"'
When annotationsString is the string I got is like this:
IFS=','
annotationsString=''
read -ra annotations <<< "$MARATHON_ALLOW_ANNOTATIONS"
pos=$((${#annotations[*]} - 1))
last=${annotations[$pos]}
for annotation in "${annotations[@]}";
do
annotationsString="${annotationsString}com.salute.tests.utils.${annotation}"
if [[ $annotation != $last ]]
then
annotationsString="${annotationsString} "
fi
done
annotationsString=$(echo ${annotationsString} | tr ' ' ',')
And this string equals:
com.hh.tests.utils.ONE_ANNOTATION,com.hh.tests.utils.TWO_ANNOTATION
but on output i have error:
adb shell '/bin/sh -c "CLASSPATH=\$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -w --no-window-animation -e clearPackageData false -e annotation com.hh.tests.utils.ONE_ANNOTATION' 'com.hh.tests.utils.TWO_ANNOTATION -e targetInstrumentation ru.hh.hhh.test/com.kaspersky.kaspresso.runner.KaspressoRunner androidx.test.orchestrator/.AndroidTestOrchestrator"'
as you can see, there is no comma, but it appeared ' '
How I can input annotationsString
with comma in bash command ?
IFS=',' adb shell 'blabla'$annotationsString'blabla'
You set IFS
to comma and $annotationsString
is not quoted, so the command is split on comma into two words on comma.
How I can input annotationsString with comma in bash command ?
You should quote the expansion adb shell 'blabla'"$annotationsString"'blabla'
. You should check your scripts with shellcheck, which will detect such errors.