shell - CGI shell 脚本中的头文件(或包含文件)
问题描述
我有多个用于 CGI 的 shell 脚本文件,它们都需要使用相同的定义名称/变量。有没有办法创建一个包含在所有这些 shell 脚本文件中的“头”文件。以下是示例:
头文件
#!/bin/sh
name_A="Amazon"
name_B="Beta"
identity_A="/opt/tmp/abc.env"
identity_B="/opt/temp/abc.env"
显示.sh
#!/bin/sh
#instead of define all those variable, is there a way to 'include' header.sh
if grep -Fx "$name_A" $identity_A ; then
echo "$identity_A"
elif grep -Fx "$name_B" $identity_B ; then
echo "$identity_B"
fi
退出.sh
#!/bin/sh
#instead of define all those variable, is there a way to 'include' header.sh
if !(grep -Fx "$name_A" $identity_A); then
exit $?
fi
退出b.sh
#!/bin/sh
#instead of define all those variable, is there a way to 'include' header.sh
if !(grep -Fx "$name_B" $identity_B); then
exit $?
fi
解决方案
推荐阅读
- javascript - 来自 JS 类的“意外令牌”?
- python - 如何使用一个 if 语句评估多个变量
- google-api - Gmail API 推送通知重复消息 ID
- vue.js - Vue:如何:将不同的处理程序传递给同一组件的 @click 事件?
- idris - Idris 类型不匹配,即使来自模板也会发生
- typescript - VS Code - 获取当前选定的 TreeItem
- reactjs - 如何将组件属性访问到另一个组件文件中
- r - 在 R 中复制模拟和 For 循环
- python - 学校项目:通过http请求通过python上传/下载文件到localhost(上传的文件是可见的)
- spring - 可分页页面大小大于 2000?抛出异常