所以我编写了一个 bash 脚本,它在 MAC 上完美运行,但在 Windows 上即使安装了 cygwin 和 CURL 也无法运行,下面是我收到的错误
$ ./r.bash
Project name:
imiodrag
': not a valid identifiertheme_name
: No such file or directory
mkdir: cannot create directory `\r': File exists
>>>>>>>>>>Downloading wordpress...
Warning: Failed to create the file latest.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
158 158 0 158 0 0 531 0 --:--:-- --:--:-- --:--:-- 531
curl: (23) Failed writing body (0 != 8)
tar (child): latest.tar.gz\r: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
rm: cannot remove `latest.tar.gz\r': No such file or directory
>>>>>>>>>>Moving files...
mv: cannot stat `start-project/wp-base/': No such file or directory
: No such file or directorycontent/themes/
: No such file or directoryib/
>>>>>>>>>>Now downloading jquery...
Warning: Failed to create the file jquery-latest.min.js
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
1 93436 1 1127 0 0 17888 0 0:00:05 --:--:-- 0:00:05 17888
curl: (23) Failed writing body (0 != 1127)
: No such file or directory./
' is not a git command. See 'git --help'.
Did you mean this?
init
' did not match any files
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Lili@Lili-PC.(none)')
: No such file or directory./../../
脚本如下:
#!/bin/bash
echo ""
echo "Project name: "
read theme_name
cd "../"
mkdir "$theme_name"
cd "$theme_name"
echo ">>>>>>>>>>Downloading wordpress..."
echo ""
curl -O http://wordpress.org/latest.tar.gz
tar --strip-components=1 -zxf latest.tar.gz
rm latest.tar.gz
cd "../"
echo ">>>>>>>>>>Moving files..."
echo ""
mv start-project/wp-base/ "$theme_name/wp-content/themes/$theme_name"
cd "$theme_name/wp-content/themes/$theme_name"
cd js/lib/
echo ">>>>>>>>>>Now downloading jquery..."
echo ""
curl -O http://code.jquery.com/jquery-latest.min.js
cd ../../
git init
git add .
git commit -a -m "First commit"
cd ../../../../
rm -rf start-project
那么为什么在 Windows 上不起作用?有什么建议吗?我在 Windows 7 64 位旗舰版上
答案1
正如前面提到的,Cygwin 需要 Unix 行尾。因此,您不必用回车换行符 (CRLF) 来结束每行,而是只需用换行符 (LF)(又称换行符)来结束每行。
许多文本编辑器允许您转换行尾。Cygwin 本身可以使用命令行工具转换文件d2u
。