5

I have a bash specific code in my bash profile:

$ cat ~/.bash_profile
#!/usr/bin/env bash

echo "SHELL: $SHELL"
function printfiles() {
  while IFS='' read -r _file || [[ -n "$_file" ]]; do
    echo "file: ${_file}"
  done < <(ls)
} && export -f printfiles

The < <(FUNCTION) is bash specific syntax, unsupported by sh. When I log in to a remote machine with ssh:

$ ssh my.remote
me@xxx.xx.xxx.xx's password: 
Last login: Fri Nov 17 11:27:39 2017 from yyy.yy.yy.yy
sourcing /home/me/.bash_profile
SHELL: /bin/bash

It works fine. Now I want to log in again but forwarding my X11:

$ ssh -X my.remote
me@xxx.xx.xxx.xx's password: 
sh: printfiles: line 2: syntax error near unexpected token `<'
                                                              sh: printfiles: line 2: ` done < <(ls)'
                                                                                                     sh: error importing function definition for `printfiles'
               sh: printfiles: line 2: syntax error near unexpected token `<'
                                                                             sh: printfiles: line 2: ` done < <(ls)'
                                                                                                                    sh: error importing function definition for `printfiles'
                              sh: printfiles: line 2: syntax error near unexpected token `<'
                                                                                            sh: printfiles: line 2: ` done < <(ls)'
                                                                                                                                   sh: error importing function definition for `printfiles'
                                             sh: printfiles: line 2: syntax error near unexpected token `<'
                                                                                                           sh: printfiles: line 2: ` done < <(ls)'
    sh: error importing function definition for `printfiles'
                                                            Last login: Fri Nov 17 11:28:51 2017 from yyy.yy.yy.yy
sourcing /home/me/.bash_profile
SHELL: /bin/bash

I have no clue what is happening, it seems that when I do the X11 forwarding somehow the sh shell is used over bash. Why so, how to solve that?

0

If I see inconsistencies between -X and -x logins, I suspect:

  1. Differences among .bash_profile/.profile and .bashrc - see excellent discussion at https://serverfault.com/a/261807/116193
  2. Interaction of my local environment with the remote - I debug this by stripping out controlling the local environment, such as with env -i ssh ...

Also: generally, I like to use -x to troubleshoot many of these types of things. You may be able to configure the Shell on the server side to enable the trace (-x) on login.

If I think of others, I'll update.

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.