1. Summary
I want to print variables from loop.
If I place echo $i
after command from loop:
elif I place echo $i
before command from loop:
I don't find:
- why is this happening,
- how I can print variable before command.
2. What the script should do
I use HTMLTidy for validate my HTML.
I want, that HTMLTidy validate all HTML in folder output
and subfolders of this folder.
See simply configuration of my project.
Working equivalent Windows batch script:
@echo off
FOR /R %%i IN (*.html) DO echo %%i & tidy -mq %%i
3. Steps to reproduce
I print in console:
cd output && bash ../tidy.sh
../tidy.sh
— path to my script, see simply configuration.
4. exit code 0
If tidy.sh
:
shopt -s globstar
for i in **/*.html; do
tidy -mq $i
echo $i
done
$ cd output && bash ../tidy.sh
line 8 column 9 - Warning: trimming empty <span>
SashaInFolder.html
line 8 column 9 - Warning: trimming empty <div>
subfolder/SashaInSubFolder.html
The command "cd output && bash ../tidy.sh" exited with 0.
Done. Your build exited with 0.
5. exit code 1
Elif:
shopt -s globstar
for i in **/*.html; do
echo $i
tidy -mq $i
done
$ cd output && bash ../tidy.sh
SashaInFolder.html
line 8 column 9 - Warning: trimming empty <span>
subfolder/SashaInSubFolder.html
line 8 column 9 - Warning: trimming empty <div>
The command "cd output && bash ../tidy.sh" exited with 1.
Done. Your build exited with 1.
6. Not helped
- I try printf instead of echo → I get same behavior.
- I can't find answer to my question in Google.
tidy -mq "$i" || echo "tidy failed with $? on $i"
, in place of your currenttidy
command. It might help to explicitlyexit 0
reaching the end of your script.