0

When doing:

#!/bin/bash
function01() {
    echo "Func01"
}
function02() {
    echo "Func02"
}
function03() {
    echo "Func03"
}
clear
function01
function02
#sudo su
function03

and calling as:

curl http://192.168.1.1:80/myScript.sh | sudo bash  

or

curl http://192.168.1.1:80/myScript.sh | bash  

It run ok but if uncommenting the line:

#sudo su

above then it throw the error:

bash: line 1: function03: command not found
Mark
  • 91
  • 1
  • 9
  • Erm, what are you even expecting `sudo su` to do in that context? BTW, you really should use `sudo -i`, not sudo su`. – Zoredache May 20 '19 at 20:09
  • @Zoredache There is a block of code that doesnt run with just sudo context then doing sudo su to become root and execute the block, I dont know about sudo -i , i will try with it, thanks. By the way the code i wrote is really wrong ? – Mark May 20 '19 at 20:21
  • 1
    If you are expecting `sudo` to be able to run that function, it isn't going to work. Those functions exist in the scope of the current shell running that script. If you use `sudo` that spawns a completely new shell. Your functions are not copied to the new shell. – Zoredache May 20 '19 at 23:11
  • @Zoredache Im doing sudo echo 'something' > /etc/fstab and it dont work, need be with real root and I tried using sudo -i on the minimal example as you told on this body question but the error remains the same – Mark May 20 '19 at 23:31
  • @Zoredache understood, then sudo su is creating another context, then i believe need call sudo -i before calling script with curl/bash and removing all sudo after it, thanks – Mark May 20 '19 at 23:35
  • Another person with echo /etc problems: https://stackoverflow.com/q/84882 – Mark May 20 '19 at 23:44

0 Answers0