shellcheck --version or "online"): 0.4.7#!/usr/bin/env bash
if [ "$( sudo -v )" ]; then
sudo mv terraform /usr/bin/terraform
else
terraform() { "${TRAVIS_BUILD_DIR}/terraform" "$@"; }
export -f terraform
fi
Line 4:
sudo mv terraform /usr/bin/terraform
^-- SC2033: Shell functions can't be passed to external commands.
Line 6:
terraform() { "${TRAVIS_BUILD_DIR}/terraform" "$@"; }
^-- SC2032: Use own script or sh -c '..' to run this from sudo.
No issues detected!
I'm open to the fact that I might be doing something wrong, but I think this is a false positive. I'm conditionally creating the function, so it shouldn't even exist at the point I'm trying to run sudo instead.
I also realise this might be very hard to detect, and I will use a directive for now.
I think if you or some calling script wrap your whole code in brackets it will create the function and export it then check the condition so I think it's a valid warning. You should probably just re-name your function.
You're right, false positive. I think this is a result of the simple variable analysis shellcheck has. It figures that terraform was defined as a function, and used in sudo, even though they are in separate branches. I think you'ld have to ignore this unfortunately. I'm thinking of making the data flow analysis better, but that will take some time.
Most helpful comment
You're right, false positive. I think this is a result of the simple variable analysis shellcheck has. It figures that
terraformwas defined as a function, and used insudo, even though they are in separate branches. I think you'ld have to ignore this unfortunately. I'm thinking of making the data flow analysis better, but that will take some time.