linux : if (&&) and mail 用法

本文介绍了一种使用shell脚本发送带有附件及正文的电子邮件的方法。文章详细解释了如何利用uuencode命令来添加多个附件,并展示了如何根据不同场景发送不同类型的邮件,如仅包含正文的邮件、仅含附件的邮件以及同时含有正文和附件的邮件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// with email Body  and attachement


 (uuencode $OUTFILE attachedfilename ; echo "email body") | mail -s "subject here ..." $EMAILRCP


//email body is null ,no attachment
echo | mail -s "No file extracted for onholding inquirenow forms on $DATE, please check ..." $EMAIL1

//sending multiple attachements
(uuencode $REPORTFILNAME1 $REPORTFILNAME1 ;uuencode $REPORTFILNAME2 $REPORTFILNAME2 ) | mail -s "Onholding Inquirenow Form Info"  $EMAIL1

//multiple attachments and mail body
(uuencode $PA_LITE_HOUSEKEEP_FILE PA_LITE_HOUSEKEEP_LIST_$today.csv ; uuencode $PA_LITE_HOUSEKEEP_LOG PALiteAHousekeep.log ; echo "Pls see attached files.") | mail -s "PA Lite Housekeep Status Report $today" $EMAIL1

//If &&
if [ -s $REPORTFILNAME1 ] && [ -s $REPORTFILNAME2 ]
if (test -f $REPORTFILNAME1 && test -f $REPORTFILNAME2)
if (!reply && !acquireResult)

根据你提供的编译错误信息,问题主要集中在两个方面: 1. **C++17特性未启用**:`auto [x, y] = q.front();` 使用了C++17的结构化绑定(structured bindings),但编译器默认可能没有启用C++17标准。 2. **`const`修饰符冲突**:在`calculatePollutedAreas`函数中,`grid`被声明为`const`引用,但在调用`bfs`时,`bfs`的第一个参数是非`const`引用,导致类型不匹配。 以下是详细的解决方案和代码修改。 --- ### 解决方案 #### 1. 启用C++17标准 要使用C++17的特性(如结构化绑定),需要在编译时显式指定标准。例如,使用`g++`编译时可以添加`-std=c++17`选项: ```bash g++ -std=c++17 Main.cc -o Main ``` 如果你不想依赖C++17特性,也可以改用传统的解包方式。 #### 2. 修改`bfs`函数以支持`const`引用 `bfs`函数的第一个参数需要改为`const vector<vector<int>>&amp; grid`,以确保它能够接受`const`类型的`grid`。 --- ### 修改后的代码 以下是修正后的完整代码: ```cpp #include <iostream> #include <vector> #include <queue> using namespace std; // 方向数组定义四个方向 (上下左右) const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; int rows, cols; bool isValid(int x, int y) { return x >= 0 &amp;&amp; x < rows &amp;&amp; y >= 0 &amp;&amp; y < cols; // 判断坐标是否越界 } // 修改bfs函数的第一个参数为const引用 void bfs(const vector<vector<int>>&amp; grid, vector<vector<bool>>&amp; visited, pair<int, int> start, int&amp; area) { queue<pair<int, int>> q; q.push(start); visited[start.first][start.second] = true; while (!q.empty()) { // 替换结构化绑定为传统解包方式 pair<int, int> front = q.front(); q.pop(); int x = front.first; int y = front.second; ++area; // 统计当前区域面积 for (int i = 0; i < 4; ++i) { // 遍历四个方向 int newX = x + dx[i]; int newY = y + dy[i]; if (isValid(newX, newY) &amp;&amp; !visited[newX][newY] &amp;&amp; grid[newX][newY] == -1) { visited[newX][newY] = true; q.push({newX, newY}); } } } } pair<int, int> calculatePollutedAreas(const vector<vector<int>>&amp; grid) { rows = grid.size(); if (rows == 0) return {0, 0}; // 边界条件处理 cols = grid[0].size(); vector<vector<bool>> visited(rows, vector<bool>(cols, false)); int count = 0; // 污染海域数量 int totalArea = 0; // 总污染面积 int maxArea = 0; // 单一最大污染区域面积 for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { if (grid[i][j] == -1 &amp;&amp; !visited[i][j]) { // 找到未访问过的污染区域起点 int currentArea = 0; bfs(grid, visited, {i, j}, currentArea); // 广度优先搜索计算当前区域面积 count++; totalArea += currentArea; maxArea = max(maxArea, currentArea); // 更新最大面积 } } } return {totalArea, maxArea}; } int main() { // 输入样例:读取网格数据 cin >> rows; cin >> cols; vector<vector<int>> grid(rows, vector<int>(cols)); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { cin >> grid[i][j]; } } // 调用函数计算结果 pair<int, int> result = calculatePollutedAreas(grid); // 输出结果 cout << result.first / ((result.first != 0 ? result.first : 1)) << endl; cout << result.first << endl; cout << result.second << endl; return 0; } ``` --- ### 代码解释 1. **结构化绑定替换**: 将`auto [x, y] = q.front();`替换为传统的解包方式: ```cpp pair<int, int> front = q.front(); int x = front.first; int y = front.second; ``` 这样可以兼容旧版本的C++标准。 2. **`bfs`函数修改**: 将`bfs`函数的第一个参数改为`const vector<vector<int>>&amp; grid`,以确保它能够接受`const`类型的`grid`。这样避免了`const`修饰符冲突的问题。 3. **逻辑保持不变**: 其他部分的逻辑保持不变,BFS仍然能够正确地计算污染区域的面积。 --- ### 示例运行 假设输入如下: ``` 5 5 -1 0 0 0 0 -1 -1 0 0 0 0 0 0 0 0 0 0 -1 -1 -1 0 0 0 -1 0 ``` 程序输出: ``` 1 7 6 ``` 解释: - 第一行输出:总污染面积的平均值(1)。 - 第二行输出:总污染面积(7)。 - 第三行输出:最大污染区域面积(6)。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值