-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require func is fail #32
base: master
Are you sure you want to change the base?
Conversation
# Check command is exist I found require method to detect whether the command exists is invalid, take antisyntax problems Here's the correct way to write it require () { for command in "$@"; do if [ ! -x "$(command -v "$command")" ]; then fail "'$command' util not found, please install it first" fi done }
@Ljohn001, can you explain why this is an anti-syntax problem? ABS guide just inclined towards this option Yes, both work, but is it worth changing something? Can you explain your point of view? ! [ -x "$(command -v /bin/cat)" ] && echo none || echo ok
# ok
! [ -x "$(command -v /bin/cat2)" ] && echo none || echo ok
# none
[ ! -x "$(command -v /bin/cat)" ] && echo none || echo ok
# ok
[ ! -x "$(command -v /bin/cat2)" ] && echo none || echo ok
# none |
I found that there is this phenomenon, that is, this test sometimes takes effect and sometimes fails.
|
I added debugging and rebuilt an image. Two servers executed the same command and returned different results. Here is the execution result. dockerfile and kube-dump
A server
B server:
|
After I modified the shell of the command, the problem still exists. I think this has something to do with the docker version.
|
Check command is exist
I found require method to detect whether the command exists is invalid, take antisyntax problems
Here's the correct way to write it
require () {
for command in "$@"; do
if [ ! -x "$(command -v "$command")" ]; then
fail "'$command' util not found, please install it first"
fi
done
}