I have array of files , example file=[a.yml, a.json,b.yml,b.json]
. I'm iterating using for
loop. I need to exclude the .json
files from being executed when it has both .yml
or.yaml
and .json
in the array. but if I have only .json
in the array (example [a.json,b.json]
, it needs to pass through the loop. Is that possible with shell script ?
Basically i'm trying to compare the strings in an array and exclude the duplicate dynamically.
Is this possible with shell ?
filename=$(git show --pretty="format:" --name-only $CODEBUILD_RESOLVED_SOURCE_VERSION)
echo "$filename"
mkdir report || echo "dir report exists"
for file in ${filename}; do
echo ${file}
ext=${file##*.}
if [ $ext == "yaml" ] || [ $ext == "yml" ] || [ $ext == "json" ]; then
if [ ${file} != "buildspec.yml" ] && [ ${file} != "stackupdatebuildspec.yml" ] && [ ${file} != "specs.json" ]; then
stack=$(echo ${file} | cut -d "." -f 1)
stackName="${stack//[\/]/-}"
echo ${stackName}
howmany() { echo $#; }
numOfFilesValidated=$(howmany $listOfFilesToScan)
echo "=========================================== Syntax validation started =============================================================="
cfSyntaxLogFile="cf-syntax-validation-output"
numOfFailures=0
numOfValidatedFiles=0
for file_to_scan in $listOfFilesToScan; do
if [[ $(cfn-lint -t "$file_to_scan" --parameter-values-path "${stack}.json" --append-rules ./append_rules --override-spec ./over_ride_spec/spec.json |& tee -a $cfSyntaxLogFile) == "" ]]; then
echo "INFO: Syntax validation of template $file: SUCCESS"
((numOfValidatedFiles++))
else
echo "ERROR: Syntax validation of template $file: FAILURE"
((numOfFailures++))
fi
done'''
echo
commandyml
suffix files in your question text but your code also considers theyaml
suffix. If this is required please say so in your text.