0

I have a variable: pkgname=com.google.android.youtube

And the command is

su -c "stockapp=$(pm path $pkgname | grep base | sed 'sed 's/package://g')"

I have checked the variable is passed inside the double quotes but not to $() How can I pass the variables there there??

2
  • My original command is pkgname=com.google.android.youtube And the command is su -c "stockapp=$(pm path $pkgname | grep base | sed 'sed 's/package://g')" I have checked the variable is passed inside the double quotes but not to $() How can I pass that there?? Commented Oct 3, 2022 at 13:16
  • All expansions, including the command substitution, are carried out inside the double quotes before the command (su) is called. Your variable, stockapp, is set within the shell that su spawns, and then it is immediately destroyed together with the shell when it terminates. It is unclear what you want to do. Commented Oct 3, 2022 at 13:22

1 Answer 1

0

Your code doesn't make sense.

Maybe you meant:

stockapp=$(
  PKG=$pkgname su -c 'pm path "$PKG"' |
    sed  '/base/!d; s/package://g'
)

That is, run the login shell of root as root with -c and pm path "$PKG" as arguments (assuming the login shell of root is Bourne-like) and PKG=contents-of-pkgname in its environment, and process its output to remove all the lines that don't contain base, and for the other lines, remove all occurrences of package:, and assign that output to the $stockapp variable in your shell script.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.