📄 badread.sh
字号:
#!/bin/bash# badread.sh:# Attempting to use 'echo and 'read'#+ to assign variables non-interactively.a=aaab=bbbc=cccecho "one two three" | read a b c# Try to reassign a, b, and c.echoecho "a = $a" # a = aaaecho "b = $b" # b = bbbecho "c = $c" # c = ccc# Reassignment failed.# ------------------------------# Try the following alternative.var=`echo "one two three"`set -- $vara=$1; b=$2; c=$3echo "-------"echo "a = $a" # a = oneecho "b = $b" # b = twoecho "c = $c" # c = three # Reassignment succeeded.# ------------------------------# Note also that an echo to a 'read' works within a subshell.# However, the value of the variable changes *only* within the subshell.a=aaa # Starting all over again.b=bbbc=cccecho; echoecho "one two three" | ( read a b c;echo "Inside subshell: "; echo "a = $a"; echo "b = $b"; echo "c = $c" )# a = one# b = two# c = threeecho "-----------------"echo "Outside subshell: "echo "a = $a" # a = aaaecho "b = $b" # b = bbbecho "c = $c" # c = cccechoexit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -