I am developing a shell script for ubuntu linux os. I am expecting the exit code to be always 0(success), but it returns 1(if no content in the file / non-matching pattern)
Code:
# set -xeo pipefail #commented this line, still exits at first grep
set +e
for file in ${files_folder}/*.csv
do
matching_records=${base_path}/test/match.csv # Records present in local and source file
only_source_records=${base_path}/test/source.csv # Records not in local and present in source file
unique_user_ids=${base_path}/test/source_user_id.csv # user ids only from source file
cut -d, -f4 ${file} > ${unique_user_ids} # Extract user ids only from source file
grep -x -f ${unique_user_ids} ${base_path}/test/user_ids_to_delete.csv > ${matching_records}
grep -v -f ${base_path}/test/user_ids_to_delete.csv ${unique_user_ids} > ${only_source_records}
done
In the above code the first grep itself fails, if any of ${unique_user_ids}
and ${base_path}/test/user_ids_to_delete.csv
file doesn't contain any content, but i want both the grep to always return success exit code
Edit:
I tried setting set +e
at the top of the file and commented out this line set -xeo pipefail
which was there before at the start of file.