Getting sed error

前端 未结 1 1503
暗喜
暗喜 2021-02-04 09:56

I\'m new to shell scripting but getting this error and cant figure out what up.

sed: 1: \"/Users/local/Do ...\": extra characters at the end of d command
sed: 1         


        
1条回答
  •  一向
    一向 (楼主)
    2021-02-04 10:36

    Given that sed seems to think you're running a delete line command (d), you may want to output the command to see what's actually in that environment variable of yours:

    for fl in $(S_convertPath ${RESOURCE_DIR}/db)/db.changelog-*xml; do
        echo sed -i "s/HOSTNAME/${PSM_SERVER_ADDRESS}/g" $fl
    done
    

    There's a good chance the PSM_SERVER_ADDRESS is corrupting your sed command (and may need to be processed to make it clean). One way to do this (provided you have a recent enough sed) would be to use delimiters that do not appear in the environment variable, for example:

    sed -i "s?HOSTNAME?${PSM_SERVER_ADDRESS}?g" $fl
    

    Since you've accepted this answer, I may as well add the resolution for the additional problem you found. It appears that BSD sed, unlike Linux, has a requirement that you provide an extension to the -i option. So, while Linux allows:

    sed -i "sed-command"
    

    to edit in-place, the BSD variant needs to have:

    sed -i "" "sed-command"
    

    with an empty backup suffix.

    Without that, sed may use your command as the extension and your first file name as the command.

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