-2

"paste -d'|' <(echo 22)

the code is righ in command line , but I wrote it to a shell file , it's error.

enter image description here

this result :

enter image description here

How to resolve this! Thinks!

Brook Xu
  • 13
  • 1
  • 2
    Duplicate of [Difference between sh and bash](https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash) – oguz ismail Jul 05 '20 at 15:51
  • Please don't use screen shots of code/data that can be copy/pasted. Advanced readers rely on using the browser's search feature looking for keywords, errors, etc. Use the `{}` tool from the Edit menu on mouse-selected text to format as `code/data/requiredOutput/ExactErrMsgs`. Good luck. – shellter Jul 05 '20 at 17:35

1 Answers1

0

#!/bin/bash informs the shell to use bash, and when you run it with sh it does not use bash as sh is forced.

sh is way more limited than bash, so if your script uses bash logic, but is run via sh, it is not fully compatible, and errors out where sh does not understand the commands.

Ron
  • 3,697
  • 1
  • 16
  • 24
  • It's useless for me to use "#!/bin/sh", the result is the same. – Brook Xu Jul 05 '20 at 16:01
  • That is exactly what I explained. Your script is written for Bash, you are trying to run it with `sh`, and `sh` does not know what to do with all of the `bash specific` commands.. – Ron Jul 05 '20 at 16:05
  • The point is, don't use `sh` (or any command) to run your script if you want the shebang to be honored. Make the script executable and use it as the command name. If you insist on passing the script's name as an argument, use `bash`, not `sh`. – chepner Jul 05 '20 at 16:22
  • I use bash, it doesn't work: xu@xu-virtual-machine:~$ cat test.sh #!/bin/bash command="paste -d'|' – Brook Xu Jul 06 '20 at 02:59