Basically, I believe that this answer here by Bruno Bronosky could answer my question...
How do I redirect output to a variable in shell?
...but the way he wrote his code confuses me.
What I need is this:
I have a vendor-proprietary script (small_script) that is really particular about which user runs it (only the logged in user).
I have a larger script that I wrote to help installs on Linux, and I want my large_script to call this small_script.
My large_script MUST be invoked by sudo (due to it installing a bunch of software)
Small_script refuses to execute, if executed by sudo or root
Possible solution is using variables:
myuser=$(whoami) sudo -Hu ${myuser} ./small_script.sh
This won't work because whoami reports as root since I just sudo'd the command
So, I need to set a variable ($myuser) who's output is the output of whoami Before I can run those lines of code so it appears that the currently logged in user is the real person executing the code.
Again, it appears that the user Bruno Bronosky has the right idea, but I'm really confused on his answer:
# my example above as a oneliner
series | of | commands | (read string; mystic_command --opt "$string" /path/to/file) | handle_mystified_file
Code that doesn't work:
sudo -Hu '# 1000' ./small_script.sh
works, but I need it to run on the currently logged in user (which may not be userid 1000).
sudo -Hu $USER ./script.sh
This fails to run, it gives an error thinking that the username is null.
myuser=$(whoami) sudo -Hu ${myuser} ./script.sh
This errors out thinking it is root.