linux - 用于检查简单打字稿文件中的值的 Shell 脚本
问题描述
我有一个简单的 TS 文件
环境.ts
其中包含
export const BUILD_SDK = false
export const DUMMY_PRESET = false
我有 build.sh 脚本来构建我们的 SDk。
我想编写一个shell 脚本(build.sh),如果 env.ts 中的值在构建之前为 false,则会引发错误。
有人可以帮我找出一种方法吗?
根据 Flashtube 的回答进行更新
所以我尝试了这个
#!/bin/bash
# With head -n 2 env.ts we get the first line of env.ts
# With cut -d " " we split the line at every space
# With -f 5 we specify we want the 5th spit value, in this case the boolean value
# If that is equals to true, we echo an error and pipe it to the error output with 1>&2 and exit with exit status 64
if [[ $(head -n 2 App/env/index.tsx | cut -d " " -f 5) = "false" ]]; then
echo "Error! check env variables and set it to true" 1>&2;
exit 64;
fi
我的环境文件看起来像这样
//Please inform if you do any changes in this file so that we can update build script
export const SDK_BUILD = false
但这没有用
解决方案
您可以使用以下 bash 脚本
#!/bin/bash
# With head -n 1 env.ts we get the first line of env.ts
# With cut -d " " we split the line at every space
# With -f 5 we specify we want the 5th spit value, in this case the boolean value
# If that is equals to true, we echo an error and pipe it to the error output with 1>&2 and exit with exit status 64
if [[ $(head -n 1 env.ts | cut -d " " -f 5) = "false" ]]; then
echo "Error!" 1>&2;
exit 64;
fi
现在我们可以检测该值是假还是真。
推荐阅读
- grep - 一个的 grep 输出并在另一个 grep 中搜索
- c# - xml.Load - 根级别的数据无效。第 1 行,位置 1
- javascript - 当我期望一个数组时,Fetch 返回承诺
- php - 我想在遍历获取的行时创建二维数组
- node.js - 异步函数中未定义的返回数据
- reactjs - 使用 map 函数填充表时返回 2 行
- php - 字符串函数:preg-replace
- python - 我们可以从没有实例化的类中调用方法吗
- intel - Perf 事件的含义是什么:dTLB-loads 和 dTLB-stores?
- sql - 在 TO_CHAR 的 Select 语句中设置默认列值