1

I'm trying to run commands in a script that needs to be run as superuser. I tried doing this with here documents but wasn't successful. ( I used to be able to use it with tsu in Termux).

Does anyone know a reason why it shouldn't work or a way to get it to work.

Here is the code that used to work but doesn't work anymore.

#!/data/data/com.termux/files/usr/bin/bash
... begining of script Just some regular commands

sudo touch s
tsu << EOF
    echo "Test" > s
    exit
EOF

echo after here doc

The results currently from this script is

echo "Test" > s
exit
after here doc

The 2 first lines should not appear at all and they should be in the file s. But the file s is empty.

I have also tried the following code but with the same results.

sudo touch s
sudo -s << EOF
    echo "Test" > s
    exit
EOF

echo after here doc

I have also googled this and haven't found anything to help me. All suggestion work in regular linux but not in Termux. Here is one example of what I have tried.

Any suggestion or help will be appreciated.

5
  • I explained the behavior here: github.com/topjohnwu/Magisk/issues/1463#issuecomment-506874581 – Irfan Latif Oct 22 '20 at 20:15
  • I'm not sure I fully understand what you wrote there. Is there anyway I can accomplish what I'm trying to do? I would like to be able to run some commands in a script as root but not with sudo. The reason is that I'm having an issue with the PWD having (unreachable) prefixed to the path. See here from @isrgish. For tsu I have found a solution but when I try to run with sudo I still get the (unreachable) prefix. – Sruly Oct 22 '20 at 22:17
  • remove all formatting whitespaces – alecxs Oct 23 '20 at 9:24
  • @alecxs That doesn't seem to help. – Sruly Oct 23 '20 at 14:54
  • okay forget it, i just remembered how i fixed some issues with mksh here documents. after reading github it's clear that termux su does not support that usage (like expected from linux su) you must run su -c <cmd> instead (like for magisk su) – alecxs Oct 23 '20 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.