Why doesn't my shell command using curly/smart

2020-05-03 10:58发布

问题:

I have written the following shell script:

#!/bin/bash
total=0
echo “Please enter 10 numbers >”
read VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9 VAR10
total=$((VAR1+VAR2+VAR3+VAR4+VAR5+VAR6+VAR7+VAR8+VAR9+VAR10))
echo $total

Running echo in the command line command e.g. (see below) echoes the phrase fine

echo "Please enter 10 numbers >”

But when I try to run the shell script the text isn't echoed. The script works, if I run it and type in 10 numbers the correct total is returned, but this is not useful if you don't know to type in the numbers! I have double checked that /bin/bash is correct by running

echo $SHELL

which returns /bin/bash so I'm not sure what the problem might be.

回答1:

This is caused by using "quotes" that don't actually have syntactic meaning to your shell. Consequently, >” is redirecting the output of your echo command into a file named .


On MacOS

Go to "System Preferences", then to "Keyboard". Select the "Text" tab, then uncheck "Use smart quotes and dashes".


With Microsoft applications

Don't use Office apps to edit code, and don't mail code through Outlook or similar. That said, if you must type code into an Office app without it being munged, enter AutoCorrect options; select the AutoFormat tab, and uncheck "Straight quotes with smart quotes"