#!/usr/bin/env bash n=$(( RANDOM % 100 )) if [[ n -eq 42 ]]; then echo "Something went wrong" >&2 echo "The error was using magic numbers" exit 1 fi echo "Everything went according to plan"
时间: 2024-04-19 15:29:33 浏览: 56
hbcxx:使用“#!/ usr / bin / env hbcxx”使C ++源代码可执行-开源
这是一个 Bash 脚本,它生成一个随机数 n,然后检查 n 是否等于 42。如果 n 等于 42,它会输出 "Something went wrong",并将 "The error was using magic numbers" 写入标准错误输出。最后,它会退出状态码 1。如果 n 不等于 42,它会输出 "Everything went according to plan"。
阅读全文