[英]run linux command succeed but failed in .sh file. “No such file or directory ”
我寫了一個Linux命令,它可以在命令行中完美運行:
/bin/netstat -an | grep '3306' | sed 's/.*/[MYSQLMON]&/' > /home/bbWifiExt/logs/WIFIMonitor.log
但是,當我將此代碼復制到.sh並運行.sh文件時,我得到了:
沒有相應的文件和目錄
誰能告訴我為什么? 非常感謝。
您必須將其稱為
sh mycommand.sh
或使您的Shell腳本可執行。 插入#! /bin/sh
#! /bin/sh
或#! /bin/bash
#! /bin/bash
作為第一行,
chmod +x mycommand.sh
打電話之前
mycommand.sh
如果腳本的第一行像
#!/bin/sh
和執行位設置即
chmod +x script.sh
對於我的情況(從Windows重命名並將文件復制到Linux),解決方案是:
dos2unix script.sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.