linux - 编译后运行 shell 脚本时出现问题
问题描述
我创建了一个 shell 脚本,当从命令行调用它并给它每个参数时,它运行完美。但是,当我使用我的 make 文件编译脚本时,它会忽略没有给出参数的情况并且什么也不打印。
如果没有通过命令行传入参数,我的逻辑是否有问题?
#!/bin/bash
# findName.sh
searchFile="/acct/common/CSCE215-Fall19"
if [[ $1 = "" ]] ; then
echo "ERROR ARGUMENT NEEDED"
exit 2
fi
grep -i $1 ${searchFile}
if [[ $? = "1" ]] ; then
echo "$1 was not found in ${searchFile}"
fi
编辑
#makefile for building
findName: main.o
g++ -g main.o -o findName
# main
main.o: main.cpp
g++ -c -g main.cpp
clean:
/bin/rm -f findName *.o
backup:
tar cvf proj.tar * cpp Makefile *.sh readme
主文件
#include <string>
#include <cstdlib>
int main(int argc, char* argv[])
{
std::string command = "./findName.sh";
if(argc == 2)
std::system((command + " " + argv[1]).c_str());
}
解决方案
推荐阅读
- javascript - 如何从 React Native 中的 Reference 数据类型获取 Firebase Firestore 中的数据
- c++ - 输出的简单重定向与实现记录器
- asp.net-core - 为什么 Newtonsoft [JsonIgnore] 停止在 asp core mvc 中工作
- regex - 16位身份证的正则表达式如何写,规则如下?
- javascript - 为什么 obj.constructor.prototype 并不总是等于 obj.__proto__?
- javascript - 如何将用于 React SPA 的 Paypal Javascript SDK 与后端服务器验证集成?
- macos - IDE 不尊重 macOS 中的环境变量
- c - 是否可以将结构指针转换为c中的函数指针?
- c# - 如何在 Blazor 中通过 Entity Framework Core 运行原始 SQL 查询
- firebase - 如何解决此错误“无法分配'用户'类型的值?' 键入“字符串?”?