[quote=bakunin;302990251]
In general it is usually a good idea to just post the information instead of telling us about it. The reason is: being a newcomer (as per your own admission) you might lack the knowledge of what is vital information and what is not. I hear you but this debug output is very simplistic. I am new to bash but not to software development/script writing. But I will generate and post some output below. The output is filenames - that's it (no errors, no mysterious codes, just names of files, 108 of them) - and I'm throwing them up against cat and cat is not doing anything with them. Show the scripts code (you did that), then run it and copy its output from start to end (ideally along with the return code it produced) here, enclosed in CODEtags, like this:
# ./myscript.sh
bla
foo
error: unable to make the flurbishes grommicking
# echo $?
2
Here is one more such suggestion: are you sure you want to add always to the file in question? Wouldn't you rather want to start an empty file for every run of the script and then fill the contents of all the other files to this one? Good suggestion but at this moment I am not concerned about it. Once I understand how I am not using cat correctly then I may come back to tweak the process.
If so, supposing outputarray
is an array variable containing path names AND there are no special characters (blanks, tabs, ...) in the file names you can do:
cat ${outputarray[*]} > /some/file
${outputarray[*]}
will expand to a list of all the array elements and cat
takes an (open-ended) list of filenames to process as arguments. There are some restrictions on this and if the array has several hundreds of entries this method might break eventually (the exact point depending on your systems configuration), but for a handful (anything less than hundred for sure) of filenames this works well.
I hope this helps. I definitely appreciate your input and help!
bakunin
Here is the code ...
#!/bin/bash
echo ""
echo "==============================================================================="
echo "This script copies all of the LocalConfig.pri files contents into another file."
echo "==============================================================================="
echo ""
cd /
echo "Changed directory to ..."
pwd
# Assign 'locate' results to a variable.
output=$(locate -b "LocalConfig.pri")
# Parse the $output variable into an array. Each line is a full path.
while read -r line; do outputArray+=("$line"); done <<<"$output"
# Loop through the array.
for idx in "${!outputArray[@]}"; do
# Print array element index and contents.
printf ' Output number %d is %s' "$idx" "${outputArray[idx]}"
printf '\n'
# Cat each file into one 'master' file.
echo -e "\tconcatenating\n\t\t ${outputArray[idx]} \n\tinto \n\t\t./LocalConfigMaster.pri ..."
cat "${outputArray[idx]}" >> ./LocalConfigMaster.pri
done
I highlighted the code above that is not doing anything as best as I can tell.
Here is the output (I abbreviated it because there are 108 files returned from the locate command)...
my.name@host:~/bash_scripts$ sudo ./CopyLocalConfig.sh
[sudo] password for my.name:
===============================================================================
This script copies all of the LocalConfig.pri files contents into another file.
===============================================================================
Changed directory to ...
/
Output number 0 is /fouo/project-release-develop/project/LocalConfig.pri
concatenating
/fouo/project-release-develop/project/LocalConfig.pri
into
./LocalConfigMaster.pri ...
The output highlighted above in bold, repeats for every occurrence of LocalConfig.pri (107 more times).
The script terminates without any errors. I execute ls -la
and there is no LocalConfigMaster.pri
file.