0

Is this possible to store list of packages in array using batch script.

SET array=(adb shell pm list packaages -3)
4
  • Possible duplicate: stackoverflow.com/questions/17047376/… Commented Oct 30, 2013 at 15:37
  • I changed the tag, but did you mean in a Windows batch file, as indicated by the title and the text in the question, or a bash script? Commented Oct 30, 2013 at 16:30
  • robvanderwoude.com/battech_array.php Commented Oct 30, 2013 at 17:53
  • thnks...but still I am facing problem in editing string like...package:com:xyz..if i only want com:xyz... Commented Oct 30, 2013 at 20:36

2 Answers 2

2

Although I don't know bash, this is the way to store a list of anything in a variable in Batch:

set Array=adb shell pm list packages -3
for %%v in (%Array%) do echo %%v

To group several words in the same element, enclose they in quotes:

set Array=adb "shell pm" "list packages -3"

In this case you may use this form in order to eliminate the quotes:

for %%v in (%Array%) do echo %%~v
Sign up to request clarification or add additional context in comments.

1 Comment

I show you how to iterate on the values. The echo command just show each iterated value, so you must change it by the command you want to execute. I don't know what is the command you want to execute (I don't know bash, remember? ;-)
0
array=$(adb shell pm list packages -3)

4 Comments

Please avoid backticks... these were in use in the middle age. In the 21st century we use $(...) instead.
I am getting error like array is not defined as internal or external command in batch file.
Is adb in your PATH?
Can anyone convert this shell script in batch script Array=($(./adb shell pm list packages -3)) For var in “${array[@]}” Do Pkg=${var#p*:} Pkg=’echo –n ${pkg} | tr –d “\r” ./adb uninstall ${pkg} Done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.