Why doesn't my shell command using curly/smart quotes work?

陌路散爱 提交于 2020-06-09 06:15:09

问题


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"



来源:https://stackoverflow.com/questions/41109888/why-doesnt-my-shell-command-using-curly-smart-quotes-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!