我一直在尝试在 Windows 机器上运行 Linux shell 脚本。要在 windows 环境下运行脚本,我选择了 Cygwin。
当我第一次开始使用 cygwin 运行脚本时,我首先遇到了以下问题。
line 12: $'\r': command not found
但第 12 行没有任何命令
08 #
09 ######################################################################
10 #### PARAMETERS TO SET BEGIN
11 ######################################################################
12
13 # archive setttings
14 ARCHIVE_USER=abc # archive storage user name (default)
15 ARCHIVE_GROUP=app # archive storage user group (default)
16 ARCHIVE_PATH=/test/file # archive storage directory (default)
17 ARCHIVE_DELAY=+8
为了解决这个问题,使用了 dos2unix 命令并从旧的生成了新的 shell 脚本
当我运行这个新生成的脚本时,它再次返回错误
housekeeper.sh: 2: Syntax error: newline unexpected
以下是 dos2unix 生成的脚本。
>#!/bin/bash
>>#
>># Date : 2012-03-22 (yyyy-mm-dd)
有人可以解释一下这里的第 2 行有什么问题吗?
提前感谢您的帮助
以下是我尝试运行的脚本的顶部,这是我使用 dos2unix 命令转换后得到的脚本
>#!/bin/bash
>>#
>># Date : 2012-03-22 (yyyy-mm-dd)
>># Modified by : ABC
>># Goal : Draft version for X house keeping environment
>>#
>># Description : This script perform housekeeping of XYS products.
>>#
>>######################################################################
>>#### PARAMETERS TO SET BEGIN
>>######################################################################
>>
>># archive setttings
>>ARCHIVE_USER=user1 # archive storage user name (default)
>>ARCHIVE_GROUP=gapp # archive storage user group (default)
>>ARCHIVE_PATH=/product/file # archive storage directory (default)
>>ARCHIVE_DELAY=+8 # archive files older than delay (in days)
>>
>># purge setttings
>>PURGE_DELAY=+30 # purge files older than delay (in days)