bash if loop produces error
by sysmicuser from LinuxQuestions.org on (#5E3D9)
Hello,
The snippet of my shell script is as follows:
Code:mkdir -p /tmp/aa1
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "serviceaccounts" ]
then
echo "Uploading source serviceaccounts"
cd ${HOME}/sync-cluster/${consider_namespace}/serviceaccounts
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "secrets" ]
then
echo "Uploading source secrets"
cd ${HOME}/sync-cluster/${consider_namespace}/secrets
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "configmaps" ]
then
echo "Uploading source configmaps"
cd ${HOME}/sync-cluster/${consider_namespace}/configmaps
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "deployments & services" ]
then
echo "Uploading source deployments"
cd ${HOME}/sync-cluster/${consider_namespace}/deployments
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
cd ${HOME}/sync-cluster/${consider_namespace}/services
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fiHowever, I am getting error like below
Code:./jenkins-part-compose-structure.sh: line 63: [: missing `]'
+ -f '*.yml' ']'
./jenkins-part-compose-structure.sh: line 63: -f: command not foundWhat I basically want to do is, if there are YAML or YML file(s) are present then get their names so they can be uploaded to the artifactory.
But if the file is not present I don't want the script to fail, it could be legit not to have any particular resource.
What mistake am I making here?


The snippet of my shell script is as follows:
Code:mkdir -p /tmp/aa1
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "serviceaccounts" ]
then
echo "Uploading source serviceaccounts"
cd ${HOME}/sync-cluster/${consider_namespace}/serviceaccounts
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "secrets" ]
then
echo "Uploading source secrets"
cd ${HOME}/sync-cluster/${consider_namespace}/secrets
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "configmaps" ]
then
echo "Uploading source configmaps"
cd ${HOME}/sync-cluster/${consider_namespace}/configmaps
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fi
if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "deployments & services" ]
then
echo "Uploading source deployments"
cd ${HOME}/sync-cluster/${consider_namespace}/deployments
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
cd ${HOME}/sync-cluster/${consider_namespace}/services
if [ ! -f *.yaml || ! -f *.yml ]
then
echo "No yaml manifest file found"
else
list_of_files=$(ls -lrt|awk '{print $9}')
curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcomany.com.au/testrepovirtual/Clustersync/" -H "Content-Type: application/json" -T ${list_of_files}
fi
fiHowever, I am getting error like below
Code:./jenkins-part-compose-structure.sh: line 63: [: missing `]'
+ -f '*.yml' ']'
./jenkins-part-compose-structure.sh: line 63: -f: command not foundWhat I basically want to do is, if there are YAML or YML file(s) are present then get their names so they can be uploaded to the artifactory.
But if the file is not present I don't want the script to fail, it could be legit not to have any particular resource.
What mistake am I making here?