[Help-bash] Simple echo is printing the wrong value
From:
Bill Gradwohl
Subject:
[Help-bash] Simple echo is printing the wrong value
Date:
Tue, 3 Apr 2012 20:46:25 -0600
I can't explain the first output line of every loop, especially when compared with the second of every loop.
The lengths are correct, but the first line gives the wrong value of x.
Having the file * appear sorted above dot was also a surprise. I routinely nuked the top 2 lines for certain purposes assuming they were always dot and double dot. Now I know that's wrong.
#!/bin/bash
mkdir ./notEmpty
touch ./notEmpty/* touch ./notEmpty/notAsterisk ls -al ./notEmpty
declare loopPass=0 for x in ./notEmpty/*; do ((++loopPass)) echo Length of x=${#x}
echo Loop 1 pass ${loopPass} discovered - ${x} echo Loop 1 pass ${loopPass} discovered - '<'${x}'>' done echo cd notEmpty loopPass=0 for x in ./*; do ((++loopPass)) echo Length of x=${#x}
echo Loop 2 pass ${loopPass} discovered - ${x} echo Loop 2 pass ${loopPass} discovered - '<'${x}'>' done echo loopPass=0 for x in *; do ((++loopPass)) echo Length of x=${#x}
echo Loop 3 pass ${loopPass} discovered - ${x} echo Loop 3 pass ${loopPass} discovered - '<'${x}'>' done echo loopPass=0 for x in "*"; do ((++loopPass)) echo Length of x=${#x}
echo Loop 4 pass ${loopPass} discovered - ${x} echo Loop 4 pass ${loopPass} discovered - '<'${x}'>' done echo cd .. rm -rf ./notEmpty