head -n $ LINES在终端中工作但现在使用脚本

时间:2017-05-18 09:09:26

标签: linux bash

所以我试图限制某些东西的输出到终端的高度,例如:

template <typename NodeType, typename EdgeType>
class SparseGraph<NodeType, EdgeType>::const_iterator
{
private:
    using NodeIterator = typename SparseGraph<NodeType, EdgeType>::AdjacencyList::const_iterator;
    using EdgeIterator = typename SparseGraph<NodeType, EdgeType>::AdjacencyList::const_iterator;

    const_iterator(NodeIterator node_it, EdgeIterator edge_it, NodeIterator adjacent_begin, NodeIterator adjacent_end) : m_node_it{node_it}, m_edge_it{edge_it}, m_adjacent_begin{adjacent_begin}, m_adjacent_end{adjacent_end} {}

    const NodeIterator m_adjacent_begin;
    const NodeIterator m_adjacent_end;
    NodeIterator m_node_it;
    EdgeIterator m_edge_it;

    const_iterator& operator++(int)
    {
        //are we at the end of this edge list?
        if(m_edge_it == m_node_it->end()) {
            //move to the next node's edge list.
            m_node_it++;
            //are we past the last node's edge list?
            if(m_node_it == m_adjacent_end) {
                //loop back around to the beginning
                m_node_it = m_adjacent_begin;
            }
            m_edge_it = m_node_it.begin();
        }
        else {
            m_edge_it++;
        }
        return *this;
    }
}

现在,如果我在终端中写它,这是有效的。但由于某些原因,如果我尝试从脚本运行它,我会收到错误我会收到错误行数无效如果我使用&#34; $ LINES&#34; $ LINES ,则strong>或选项需要参数n

所以我想我的问题是,有没有办法在脚本中使用$ LINES或类似内容。

感谢您的帮助。

编辑:当我在脚本中使用它时,$ LINES不会保存任何内容

1 个答案:

答案 0 :(得分:1)

第一行脚本写:

LINES=$(tput lines)

瞧。

相关问题