I have a bash script that is supposed to take some arguments and then run in a different user:
#!/bin/bash sudo su user2 <<'EOF' echo $1 EOF
However it prints blank:
$ ./test.sh haha
I understand that it is because environment variable are reset(?). How can I pass this argument? Security wise I've heard I should not disable environment resetting. The only way comes to my mind to solve this is writing
$1 to a file and then reading it back again by user2. But I guess there should be a much better way.