shell reads file created in windows incorrectly

后端 未结 2 801
借酒劲吻你
借酒劲吻你 2021-01-14 12:47

Here is my shell script and properties file

test.sh

#!/bin/bash
source ./default.properties
echo $app_name
echo \"$app_name ==\"

de

2条回答
  •  执笔经年
    2021-01-14 13:26

    Yes, you have a DOS carriage return at the end of the line which assigns the appName variable. This control character causes the cursor to move back to the beginning of the line in most terminals.

    Good catch; most askers here don't even realize this is a problem. The bash tag wiki has a section about troubleshooting this issue.

    Many tools on Unix will show the problematic character as ^M (control-M) or its octal code \015; in hex it's character code 0x0D and in decimal it's 13.

    In the future, if you absolutely have to use a Windows editor, save with Unix line endings, transfer the file using ftp ASCII mode (not a popular or safe option these days), or run dos2unix on the file on Unix after transferring it.

提交回复
热议问题