-1

I've clearly become incapable of solving what seemed to me a simple rtfm issue. This line works fine on the command line (both zsh and bash):-

[[ -f ${HOME}/.xsessionrc.local ]] && . ${HOME}/.xsessionrc.local

When I put it in my .xsessionrc (shebanged with bash) it doesn't.

Am I misunderstanding that double square brackets should work? As I say, they do on the bash command line.

Both these lines work (when uncommented):-

It's not so much that I need that first to work as clearly I can use one of the other forms, but why doesn't it work "in script" but does when used directly from the command line? Some nuance about how XSession sources .xsessionrc?

  # F=${HOME}/.xsessionrc.local;[ -f $F ] && . $F
  # [ -f ~/.xsessionrc.local ] && .  ${HOME}/.xsessionrc.local

Thanks for your patience. I'm blind to it now. I've spent hours on this ;)

1 Answer 1

1

Use

[ -f "$HOME/.xsessionrc.local" ] && . "$HOME/.xsessionrc.local"

i.e., single square brackets and quoting the pathnames of the file.

The double square brackets is a non-standard test syntax in the bash (and other) shells. It is not clear that it is actually bash that is reading your file, and it may well be /bin/sh which may not understand the double square bracket syntax for tests.

See also:

4
  • Yes, I had the single brackets working. Quick Q. does the shebang not force the issue though in my .xsessionrc file? [[]] is documented as a bash friendly built in and it does indeed work from both zsh and bash command lines. stackoverflow.com/a/669461/37370 . In other words [[ is standard for remotely newer bash or am I misreading?
    – RichieHH
    Jan 2, 2021 at 9:27
  • 1
    @RichieHH Yes, bash and zsh and others can use [[ ... ]]. /bin/sh can not. The shell that is executing your .xsessionrc file is not your login script but whatever shell the graphical login session manager (GDM?) is picking, most likely /bin/sh since it's available on any Unix system. The /bin/sh shell may not, as I said, understand the double square bracket test syntax.
    – Kusalananda
    Jan 2, 2021 at 9:35
  • 1
    @RichieHH A #! line would not matter if the file is sourced, or executed with an explicit interpreter.
    – Kusalananda
    Jan 2, 2021 at 9:35
  • Thank you for the updates. Confusing to a degree but most evolved SW is ;) I'm not using a GDM btw, but startx from bash in a login terminal, which -> xinitrc > X11/Xsessionrc -> .xsessionc.
    – RichieHH
    Jan 2, 2021 at 9:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .