The for loop takes its iteration values from its in clause or from the content of $@; it does not read from stdin.
In your last example, the entire command's stdin is being redirected from a.txt and it produces no output because for doesn't read from stdin and its command block's commands don't either.
The read command, however, does read from stdin and that's why the while read arg; loop works.
Credit to Glenn for explaining the meaning of a for command without an in clause:
The value of $@ is empty and that is why your for loop produces no output. Redirecting a command's stdin from a file does not set $@. If you had placed that for loop in a script and executed it with some arguments, then your for loop would have printed the command line's arguments instead of the content of a.txt.
for argtowhile read arg;and it should do what you want.on each line by doing xargs -n1will not work with lines that contain odd number of'or/and odd number of".or for a in $(cat a.txt)will not work with lines that has spaces or tabs between words.for arg; do ...is equivalent tofor arg in "$@"; do .... It does not take values from the input stream, but from the positional parameters.for