0

we use unix modules and have sh softlinked to bash in system.

$ ls -al /bin/sh lrwxrwxrwx 1 root root 4 Jan 27 2016 /bin/sh -> bash 

I thought it should be the same use #!/bin/sh & #!/bin/bash, but it is different.

For example, we have bash_completion script

$ cat bash_completion _module_not_yet_loaded() { comm -23 <(_module_avail|sort) <(tr : '\n' <<<${LOADEDMODULES}|sort) } 

I try to initialize this

$ bash $ source bash_completion $ sh # switch to sh $ source bash_completion sh: bash_completion: line 3: syntax error near unexpected token `(' sh: bash_completion: line 3: ` comm -23 <(_module_avail|sort) <(tr : '\n' <<<${LOADEDMODULES}|sort)' 

So what's the problem ? why sh softlink to bash doesn't work as I expected ?

6
  • 3
    Bash detects that it has been invoked as sh and enables sh-compatibility. Commented Aug 8, 2017 at 21:12
  • It is important not to put bash-constructs into a #!/bin/sh file. See this answer. Commented Aug 8, 2017 at 21:14
  • Thank for quick answer. Can u explain more ? and give some mode code sample in answer directly so I can accept later Commented Aug 8, 2017 at 21:14
  • 2
    There's an existing question with answers that cover this ground rather comprehensively -- see the link up at the top of the question. Commented Aug 8, 2017 at 21:15
  • Item 29 at Bash manual — POSIX mode; process substitution is not available. Don't use sh if you want to use <(…). Commented Aug 8, 2017 at 21:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.