I have a directory containing files that start with a date.
for file in ./my_dir/*; do
first_line=$(head -n 1 "$file")
echo $file:$first_line
done
This prints as below, which is expected:
./my_dir/file.md:23/07/2023
When I switch the order of the $file
and $first_line
like this:
for file in ./my_dir/*; do
first_line=$(head -n 1 "$file")
echo $first_line:$file
done
The output becomes:
:./my_dir/file.md
The $first_line
is completely ignored. My expectation was it to be like this:
23/07/2023:./my_dir/file.md
I've tried changing the delimiter and the first line of the files. Using ${first_line}:${file}
, "${first_line}:${file}"
didn't work too.