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

后端 未结 6 1815
刺人心
刺人心 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:11

    No you can't. Or atleast... you can su but su will simply open a new shell at that point and when it's done it will continue with the rest of the script.

    One way around it is to use su -c 'some command'

提交回复
热议问题