can I run 'su' in the middle of a bash script?

后端 未结 6 1825
刺人心
刺人心 2021-02-04 23:43

can I change/su user in the middle of a script?

if [ \"$user\" == \"\" ]; then
  echo \"Enter the table name\";
  read user
fi

gunzip *
chown postgres *
su pos         


        
6条回答
  •  名媛妹妹
    2021-02-05 00:16

    Refer to answers in below question,

    You can write between << EOF and EOF as mentioned in answers.

    #!/bin/bash
    whoami
    sudo -u someuser bash << EOF
    echo "In"
    whoami
    EOF
    echo "Out"
    whoami
    

    How do I use su to execute the rest of the bash script as that user?

提交回复
热议问题