Context:
I want to check whether a kubernetes pod is already running. For this i am using a while loop to get the output of kubectl. Then I look for the appropriate status.
Observation:
A dummy pod is running just like this:
kubectl get pods
# dummy-7744bb4469-h2mrq 1/1 Running 0 58d
Now i execute the following command in the cli and it returns the above line containing the dummy pod
kubectl get pods | grep dummy*
# dummy-7744bb4469-h2mrq 1/1 Running 0 58d
# with "dummy" being color highlighted
So i created a while loop in a bash script which looks like this:
function check_pod_running(){
while [ $(kubectl get pods | grep $1* | grep Running | wc -l) == 0]; ...
}
# with $1 being the string dummy
However it can not grep the appropriate line and is stuck in the loop until timeout.
Using google i found this Using the star sign in grep post, which tells me to use $1.* instead of $1* and it does work, but I'd like to know why in my case? Why does it work in the cli but not in a script which executes the same command?
Edit: Solved
Thanks to Charles Duffy and his hint, that a normal unquoted grep will first look into the current directory before the piped output. The script which was running the abovementioned grep was also executing a pushd at some point, changing the current directory which coincidentally also included a file with "dummy" in its name. Apparently, it would then expand on the filename and would grep dummy.txt from the piped output of kubectl, which yields nothing.