read: Illegal option -d

前端 未结 2 1667
借酒劲吻你
借酒劲吻你 2020-12-17 16:23

Here is the offending part of my script:

read -d \'\' TEXT <<\'EOF\'
Some Multiline
text that
I would like
in 
a 
var
EOF

echo \"$TEXT\" > ~/some/f         


        
相关标签:
2条回答
  • 2020-12-17 16:38

    The -d option to read is a feature unique to bash, not part of the POSIX standard (which only specifies -r and -p options to read). When you run your script with sh on Ubuntu, it's getting run with dash, which is a POSIX shell, and not bash. If you want the script to run under bash then you should run it with bash, or give it a #!/bin/bash shebang. Otherwise, it should be expected to run under any POSIX sh.

    0 讨论(0)
  • 2020-12-17 16:42

    If you run sh and then try that command, you get:

    read: 1: Illegal option -d
    

    If you do it while still in bash, it works fine.

    I therefore deduce that your script is not running under bash.

    Make sure that your script begins with the line:

    #!/usr/bin/env bash
    

    (or equivalent) so that the correct shell is running the script.

    Alternatively, if you cannot do that (because the script is not a bash one), just be aware that -d is a bash feature and may not be available in other shells. In that case, you will need to find another way.

    0 讨论(0)
提交回复
热议问题