Changing to root user inside shell script

后端 未结 5 1339
不思量自难忘°
不思量自难忘° 2021-01-03 21:13

I have a shell script which needs non-root user account to run certain commands and then change the user to root to run the rest of the script. I am using SUSE11. I have use

5条回答
  •  醉梦人生
    2021-01-03 21:54

    Also, note that if you are changing to "root" user inside a shell script like below one, few Linux utilities like awk for data extraction or defining even a simple shell variable etc will behave weirdly.

    To resolve this simply quote the whole document by using <<'EOF' in place of EOF.

    sudo -i <<'EOF'
    ls
    echo "I am root now"
    EOF
    

提交回复
热议问题