-
-
Save mike-burns/9327099 to your computer and use it in GitHub Desktop.
HQ9+ in sh
This file contains hidden or 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/sh | |
main() { | |
hello_world=0 | |
quine=0 | |
nine=0 | |
plus=0 | |
accumulator=0 | |
while getopts hq9+ opt; do | |
case "$opt" in | |
h) | |
echo hello, world | |
;; | |
q) | |
cat $0 | |
;; | |
9) | |
echo Ninety nine bottles of beer on the wall | |
echo Ninety nine bottles of beer | |
echo etc. | |
;; | |
+) | |
accumulator=$(($accumulator + 1)) | |
;; | |
esac | |
done | |
} | |
main "$@" |
This file contains hidden or 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/sh | |
hello_world=0 | |
quine=0 | |
nine=0 | |
plus=0 | |
accumulator=0 | |
bug_args= | |
while getopts hq9+ opt; do | |
case "$opt" in | |
h) | |
bug_args="-h $bug_args" | |
;; | |
q) | |
bug_args="-q $bug_args" | |
;; | |
9) | |
bug_args="-9 $bug_args" | |
;; | |
+) | |
bug_args="-+ $bug_args" | |
;; | |
esac | |
done | |
saved_IFS=$IFS | |
IFS=' | |
' | |
for i in $(./bug $bug_args); do | |
echo $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would expect this to fail.
"$var"
is not the same as "$@" or "$*".That's why, in our case we must to
lsrc $LS_ARGS
and notlsrc "$LS_ARGS"