m*****k 发帖数: 731 | 1 my.sh file is like this:
#!/bin/bash
while getopts ":a" opt; do
case $opt in
a) echo "-a was triggered!";;
\?) echo "Invalid option: -$OPTARG" ;;
esac
done
but when I ran it several times, I got diff answers:
mymac me$ . my.sh -abc
-a was triggered!
Invalid option: -b
Invalid option: -c
mymac me$ . my.sh -abc
mymac me$ . my.sh -abc
mymac me$
any mac *nix guy can help explain why it behaves like this? | n*******s 发帖数: 149 | 2 dont have a max os.
but looks like you should run "./my.sh -abc" instead of ". my.sh -abc". In
case my.sh is not executable, run "chmod +x my.sh" to make it executable.
. is a command, similar to source command.
【在 m*****k 的大作中提到】 : my.sh file is like this: : #!/bin/bash : while getopts ":a" opt; do : case $opt in : a) echo "-a was triggered!";; : \?) echo "Invalid option: -$OPTARG" ;; : esac : done : but when I ran it several times, I got diff answers: : mymac me$ . my.sh -abc
| m*****k 发帖数: 731 | 3 it is 777, ./my.sh not work, gave error like
-bash: ./my.sh: /bin/bash: bad interpreter: Operation not permitted
I guess I need reset PATH | w*******x 发帖数: 489 | 4 Does the command >which bash
gives you /bin/bash
?
【在 m*****k 的大作中提到】 : it is 777, ./my.sh not work, gave error like : -bash: ./my.sh: /bin/bash: bad interpreter: Operation not permitted : I guess I need reset PATH
| m*****k 发帖数: 731 | 5 yes,it gave the right bash, I found out the reason, I had used textedit to
change and save the sh, then ls -al shows that the sh is rwxrwxrwx@, the
strange @ added by textedit caused this error. use nano to edit a same
content sh, everything worked. |
|