Last active
January 13, 2021 08:06
-
-
Save phith0n/808127b8d0db8742d94a560e4ecb9b02 to your computer and use it in GitHub Desktop.
一个离奇的Shell问题(请在Linux下运行,MacOS下运行会出错)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@b3324f24e6c0:/tmp# ./sample.sh -n Bob -a | |
Arg: -n | |
Arg: Bob | |
Bob | |
Arg: -a | |
-a | |
Arg: -- | |
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
opt=`getopt -a -o "n:a" --long "name:,admin" -- "$@"` | |
eval set -- "$opt" | |
while true; do | |
echo "Arg: $1" | |
echo "$1" | |
shift | |
if [[ "$1" == "" ]]; then | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output.txt里,第3行为何不是
-n
,而是下一个循环里的Arg: Bob
?