Linux shell set command All In One
erros ❌
unbound-variable
# $1: unbound variable
if (($1))
then
echo $1
# arg=$1
# tsGenerator $arg
# tsGenerator $1
# tsGenerator
else
echo "❌"
fi
#!/usr/bin/env bash
# 显示所有的已经执行的命令
# set -eux
# set -ex
# bug
set -u
echo "\$1 = $1"
echo "\$2 = $2"
# 一个参数
# $ /auto-ts-files-generator.sh 33
# 两个参数
# $ ./auto-ts-files-generator.sh 33 regular-expressions
It is well appreciated that when set -u
is active Bash will report an error if an unbound variable
is referenced, e.g.:
很好理解,当 set -u
处于活动状态时,如果引用
了未绑定
的变量
,Bash 将报告错误,例如:
https://bnikolic.co.uk/blog/bash-unbound-variable
https://replit.com/@bnwebcode/bash-unbound-variable
https://unix.stackexchange.com/questions/463034/bash-throws-error-line-8-1-unbound-variable
: bad substitution
# : bad substitution ❌
if [ -n "${$2:-}" ]; then
echo "\$2 = $2"
filename=$2
else
filename=$fallback
fi
solutions
set +u
-u Treats unset parameters as an error when substituting.
Using + rather than - causes these flags to be turned off.
https://blog.csdn.net/qq_21481459/article/details/104202174
demos
#!/usr/bin/env bash
# 显示所有的已经执行的命令
set -eux
# bug ❌ https://www.cnblogs.com/xgqfrms/p/17251644.html#5161214
# 当 set -u 处于活动状态时,如果引用了未绑定的变量,Bash 将报告错误
# set -u
echo "
标签:set,No,echo,builtin,shell,command,Yes
From: https://www.cnblogs.com/xgqfrms/p/17252980.html