首页 > 解决方案 > 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

标签: shellcgi

解决方案


推荐阅读