I want a script that I run thusly:
logphone Foo Bar Tar:I Baz:D
Which actually runs
adb -d logcat dalvikvm:I ActivityManager:W AndroidRuntime:W Foo:* Bar:* Tar:I Baz:D *:S
How do I do this with any number of parameters? Note that the order somewhat matters (Foo, Bar, etc. can’t be at the end). Bash if it matters.
I can break the steps down to
- For any number of command line arguments…
- Check each argument for a colon (
:) - If there’s no colon add
:*, otherwise leave it alone - Inject it into the command line
adb logcat dal…time:W __INJECTED_ARGS__ *:S
Try the following bash code. Don’t forget the shebang (if not /bin/bash) and
chmod +x script.sh:If you have a recent bash (see it with
bash -version), I can improve it a bit.