help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] Why `<` has to be after `while`?


From: Peng Yu
Subject: [Help-bash] Why `<` has to be after `while`?
Date: Sun, 11 Feb 2018 13:43:06 -0600

Hi,

The following example shows that `<` has to be after `while`. But
there is no such restriction of a regulate command. Is it really
necessary to have this restriction for `while`?

$ cat main.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:

tmpfile=$(mktemp -u)
seq 3 > "$tmpfile"

set -v
cat < "$tmpfile"
< "$tmpfile" cat

while read -r x
do
    echo "$x"
done < "$tmpfile"

< "$tmpfile" while read -r x
do
    echo "$x"
done
$ ./main.sh
cat < "$tmpfile"
1
2
3
< "$tmpfile" cat
1
2
3

while read -r x
do
    echo "$x"
done < "$tmpfile"
1
2
3

< "$tmpfile" while read -r x
./main.sh: line 16: while: command not found
do
./main.sh: line 17: syntax error near unexpected token `do'
./main.sh: line 17: `do'


-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]