【问题标题】:Is there a way to see the action of a shell script as it is executed? [duplicate]有没有办法在执行时查看 shell 脚本的操作? [复制]
【发布时间】:2021-10-06 19:42:57
【问题描述】:

我在这里很新,正在学习编程。 我想知道是否有办法在执行 shell 脚本时查看它的操作? 例如,我想看看这些值是如何插入到这个脚本中的变量中的。

#!/bin/bash
# Script: potenz2.sh (powers of two with a while loop)
i=0
j=1
while (( i < 12 ))
do
        j=$((j * 2))
        echo -n "$j"
        i=$((i+1))
done
echo ""

【问题讨论】:

    标签: bash


    【解决方案1】:

    set -x 放在脚本的开头,或使用该选项运行它

    bash -x potenz2.sh
    

    【讨论】:

    • 非常感谢巴尔玛。我不知道这会这么容易。有很多东西要学。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 2020-08-01
    • 2018-06-02
    相关资源
    最近更新 更多