-1

I tried to run a script in a newly opened zsh-session which was

$ perl -e "for (1 .. 80000000) { print qq#$_\n# }"

So, I needed some time to type it in, then it took some time and did nothing and after a few seconds (about 5-10s) it printed thousands of...

/etc/motd
/etc/motd
/etc/motd
/etc/motd
/etc/motd
/etc/motd
/etc/motd
/etc/motd
...

I was wondering why this happened and I thought I may run it again, but with a fewer number to go to:

$ perl -e "for (1 .. 80) { print qq#$_\n# }" 

I got this message then:

Backslash found where operator expected at -e line 1, near "motd\"
syntax error at -e line 1, near "motd\"
Missing right curly or square bracket at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

Then I tried running it again and the error-message became:

syntax error at -e line 1, near ") {"
Missing right curly or square bracket at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

and sometimes:

Having no space between pattern and following word is deprecated at -e line 1.
Backslash found where operator expected at -e line 1, near "td\"
syntax error at -e line 1, near ") {"
Missing right curly or square bracket at -e line 1, at end of line
Execution of -e aborted due to compilation errors.

though the code itself has not changed.

I was thinking it had something to do with /etc/motd in my .zshrc or something, something like "it was loading it right then", but that would only make sense if it was not appearing minutes after opening the shell.

Also, this weird behaviour appears everytime I open a new tab in "Konsole" (with zsh 4.3.17 and perl 5.14.2).

Interestingly enough, when I tried to find out my perl-version with

perl -v

and I was running the script again, it gave me:

-v
-v
-v
-v
-v
-v
...

and then errors again. echoing $_ with the konsole gives me:

$ echo $_
for (1 .. 80000000) { print qq#for (1 .. 80000000) { print qq#for (1 .. 80000000) { print qq#-v
# }
# }
# }

I just cannot figure out what is happening there. So, the question is: what's happening there?

1

In double quotes the shell will expand $_ which stands for

The last argument of the previous command. Also, this parameter is set in the environment of every command executed to the full pathname of the command.

according to the zsh man page. Because this variable takes different values, you get different results when running the same command line subsequently.

So, either use single quotes to prevent most expansions by the shell for in line perl scripts (which is a good idea):

$ perl -e 'for (1 .. 80000000) { print qq#$_\n# }'

Or, escape the dollar sign:

$ perl -e "for (1 .. 80000000) { print qq#\$_\n# }"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.