我使用 bash substitutions为输入提供简洁的单行验证,例如:
#!/bin/bash
export PARAM1=${1?Error, please pass a value as the first argument"}
# do something...
但在某些情况下,我只想在某些内容未设置时记录一条消息,然后照常继续。这可能吗?
最佳答案
也许是
test -n "$1" && export PARAM1="$1" || log "\$1 is empty!"
应该做;当且仅当 $1
不为空时,test
子句才返回 true。
关于Bash 替换 : log when variable is not set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092628/