0

While

echo pwd | bash -i

works

echo pwd | login -f root

doesn't work. I expected the login command to set some environment variables and start an interactive shell, but apparently it is somehow special.

What does the login command do so the example above doesn't work? And are there any alternatives to the login command which can be used in that way?

timakro
  • 1,739
  • 1
  • 15
  • 31

1 Answers1

0

The login command checks if it is connected to a tty before working. You can simulate a tty with the script command as answered here https://stackoverflow.com/a/1402389/3235192

echo pwd | script -qc "login -f root" /dev/null

Also works with heredoc.

script -qc "login -f root" /dev/null << EOF
pwd
EOF
timakro
  • 1,739
  • 1
  • 15
  • 31