Suppose a variable value has $ symbol (storing path of a java inner class).
I want to process it as current user as well as some other user (assume current user to be root so that I need not enter password when using the su command).
Example:
path_value=/home/username/filename\$1.class
echo ${path_value}
su username -c "echo ${path_value}"
The result of first echo:
/home/username/filename$1.class
The results of the second echo inside of su command:
/home/username/filename.class
I want to use the variable such that I would be able to process it at both places with the same value.
suimplementations and assuming the login shell of the user is Bourne-like, one can also do:su username -- -c 'printf "%s\n" "$1"' sh "$path_value"– Stéphane Chazelas Jun 27 '18 at 07:47