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

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

    You can use a here document to embed multiple su commands in your script:

    if [ "$user" == "" ]; then
      echo "Enter the table name";
      read user
    fi
    
    gunzip *
    chown postgres *
    su postgres <

提交回复
热议问题