Syntax error!
Why syntax error? It would perfectly make sense.
Further, read the article how-would-you-like-your-loops-served-today
Then I tested with the best shell ever, zsh.
It works!
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Quote:
Originally Posted by MadeInGermany
...
Logically, the same should apply ...
The documentation says:
Code:
REDIRECTION
Before a command is executed, its input and output may be redirected
using a special notation interpreted by the shell. Redirection may
also be used to open and close files for the current shell execution
environment. The following redirection operators may precede or appear
anywhere within a simple command or may follow a command. Redirections
are processed in the order they appear, from left to right.
-- excerpt from man bash
Because the statement in question is not a simple command, then syntax, design, and code prevail over what may seem logical.
I note that ksh and dash also fail to process as you desire, but, I agree, zsh seems OK with the short tests I did.
while is not an external command, it's a shell builtin. The same rules don't always apply. That you can redirect into them at all is a huge blessing and feature rather unique to Bourne-based shells.
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
Minor quibble, not a builtin, but a reserved word:
Code:
RESERVED WORDS
Reserved words are words that have a special meaning to the shell. The
following words are recognized as reserved when unquoted and either the
first word of a simple command (see SHELL GRAMMAR below) or the third
word of a case or for command:
! case do done elif else esac fi for function if in select then until
while { } time [[ ]]
I wrote by accident:
cd .
and even hit ENTER.
Then I realized this is probably the most useless command that you can imagine. Yes, perhaps it could assert that there is still a working filesystem, but I am not sure about it.
What do you think?
Can you think of any more useless commands? :) (6 Replies)
cat ~/text.xt | while read line
do
echo ${line} | perl -pe 's/(\d+)/localtime($1)/e'
done
how can i efficiently re-code the above?
also, no matter how i run this, i'm not getting the current/correct date. the contents of the "text.xt" looks like this:
SERVICES... (2 Replies)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
Hi, I came across with this line "set -x" in the beginning of a script, but i can't find one logic reason for this... should be something else after, i think.... anyone can help?
tanx (2 Replies)