0

simple code i tried from my bash script

#!/usr/bin/bash
whoami
sudo -i
whoami # this is not working, but my prompt changes to root

any help, starting with bash just now, actually i am trying to execute some sed commands through bash, but commands were not executing. If this is solved hope i could work on the remaining

#!/usr/bin/bash
sudo -i
sed -i '1 a some text' filename

same sed command works fine with command prompt but none is working, i amnot sure where i am making mistakes

Myjab
  • 924
  • 1
  • 7
  • 22
  • Close this question and reopen [your last question](https://stackoverflow.com/q/60388078/3776858). – Cyrus Feb 25 '20 at 06:05
  • the question is wrong that is why i changed it bro. found that i am not able to execute any command after sudo -i – Myjab Feb 25 '20 at 06:12
  • anyway i reopened it – Myjab Feb 25 '20 at 06:12
  • Try `sudo -e file.txt` I'm not `sudoer ` so that's all I can help. – Jetchisel Feb 25 '20 at 06:31
  • When you run `sudo -i` (whether it's interactive or in a script), it starts a *new shell*. In a script, that means the new shell isn't reading commands from the script, it's reading them from standard input. By default, standard input is your terminal. To have the script to send commands to that shell, see: [Pass commands as input to another command (su, ssh, sh, etc)](https://stackoverflow.com/questions/37586811/pass-commands-as-input-to-another-command-su-ssh-sh-etc). – Gordon Davisson Feb 25 '20 at 07:01

0 Answers0