shell---解决shell脚本中回车换行导致command not found

本文详细介绍了如何在Sublime Text和EditPlus编辑器中进行Unix换行符的设置与文件格式转换,旨在帮助开发者解决在不同操作系统间文件兼容性的问题。

sublime text

View->Line endings->Unix

editplus

Document->File Fomart(FR/LF)->Change File Format


你遇到的错误: ``` --without-http_rewrite_module: command not found ``` 说明你 **直接在终端中一行一行地执行了 `./configure` 的参数,而不是把它们作为 `./configure` 命令的一部分来运行**。 这是常见的误解:这些 `--without-xxx` 参数本身并不是命令,而是传递给 `./configure` 脚本的选项。如果你把每个参数单独放在新的一行并回车执行,Shell 会试图把这些当作独立命令去运行,于是报错: > `--without-http_rewrite_module: command not found` --- ## ✅ 正确做法:将所有配置选项作为 `./configure` 的参数一次性传入 你应该复制完整的 `./configure` 命令,并确保它是一整行(或使用 `\` 换行),像这样: ```bash ./configure \ --prefix=/opt/nginx \ --with-cc=aarch64-linux-gnu-gcc \ --without-http_rewrite_module \ --without-http_gzip_module \ --without-pcre \ --without-http_ssl_module \ --crossbuild=Linux::x86_64::unknown ``` 📌 注意: - 整个命令从 `./configure` 开始。 - 反斜杠 `\` 表示“换行继续”,不要在反斜杠后面加空格或其他字符。 - 所有 `--xxx` 都是 `./configure` 的参数,不是独立命令。 --- ### 🔍 错误示例 ❌ ```bash --without-http_rewrite_module --without-http_gzip_module --without-pcre ... ``` → 这些每一行都会被 Shell 当作一个命令尝试执行,显然不存在名为 `--without-http_rewrite_module` 的程序,所以报错。 --- ### ✅ 正确示例 ✔️ ```bash CC=aarch64-linux-gnu-gcc \ CXX=aarch64-linux-gnu-g++ \ AR=aarch64-linux-gnu-ar \ RANLIB=aarch64-linux-gnu-ranlib \ ./configure \ --prefix=/opt/nginx \ --with-cc=aarch64-linux-gnu-gcc \ --with-cpp=aarch64-linux-gnu-cpp \ --without-http_rewrite_module \ --without-http_gzip_module \ --without-pcre \ --without-http_ssl_module \ --without-http_proxy_module \ --without-http_fastcgi_module \ --without-http_uwsgi_module \ --without-http_scgi_module \ --without-mail_pop3_module \ --without-mail_imap_module \ --without-mail_smtp_module \ --without-http_upstream_ip_hash_module \ --without-threads \ --without-select_module \ --without-poll_module \ --without-kqueue_module \ --without-eventport_module \ --without-file_aio \ --without-http_dav_module \ --without-http_ssi_module \ --crossbuild=Linux::x86_64::unknown ``` ✅ 这才是正确的用法! --- ## 💡 小技巧:如何避免再次出错? ### 方法 1:使用文本编辑器写好再粘贴 先在 VS Code / Notepad / Vim 中写好完整命令,确认无误后粘贴到终端。 ### 方法 2:保存为脚本文件 创建一个脚本文件,比如 `build.sh`: ```bash #!/bin/bash set -e export CC=aarch64-linux-gnu-gcc export CXX=aarch64-linux-gnu-g++ export AR=aarch64-linux-gnu-ar export RANLIB=aarch64-linux-gnu-ranlib # 屏蔽 configure 对编译器名字的记录 sed -i 's|echo \$0 > $NGX_OBJS/ngx_auto_cc_log|#&|' auto/cc/name ./configure \ --prefix=/opt/nginx \ --with-cc=$CC \ --with-cpp=$CXX \ --without-http_rewrite_module \ --without-http_gzip_module \ --without-pcre \ --without-http_ssl_module \ --without-http_proxy_module \ --without-http_fastcgi_module \ --without-http_uwsgi_module \ --without-http_scgi_module \ --without-mail \ --without-http_upstream_ip_hash_module \ --without-threads \ --without-select_module \ --without-poll_module \ --without-kqueue_module \ --without-eventport_module \ --without-file_aio \ --without-http_dav_module \ --without-http_ssi_module \ --crossbuild=Linux::x86_64::unknown make clean && make -j$(nproc) ``` 然后运行: ```bash chmod +x build.sh ./build.sh ``` 这样就不会误操作了。 --- ## 🛠️ 验证是否成功 编译完成后检查二进制: ```bash file objs/nginx ``` 输出应包含: ``` ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, ... ``` 表示这是一个有效的 AArch64 可执行文件。 --- ###
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值