0

My login script ~/.profile ends with the command

exec startx > ~/.xsession-errors 2>&1

I would like to run a second command foo when startx is done so I tried

exec { startx > ~/.xsession-errors 2>&1; foo; }

but that results in a syntax error. Any clues?

  • 2
    How about exec sh -c 'startx > ~/.xsession-errors 2>&1; foo' – glenn jackman Jul 8 '15 at 20:43
  • What about putting it in your shell's .logout file? Or in your ~/.xsession file? – Jeff Schaller Jul 8 '15 at 20:51
  • @JeffSchaller As far as I understand, ~/.bash_logout is only run when exit or Ctrl-D is invoked. – August Karlstrom Jul 8 '15 at 21:15
  • @glennjackman That will indeed work, thanks! However, I think yaegashi's solution is bit easier to read. – August Karlstrom Jul 8 '15 at 21:21
1

It won't return to the script when exec'ed command terminates. Therefore you can use exec only for the last command run in the script.

startx > ~/.xsession-errors 2>&1
exec foo
# You get here if exec foo failed
echo "Unable to exec foo" >&2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.