Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从用户输入一个字符并将相应的 ascii 值显示到屏幕上。这是我的代码。如果有任何错误,请更正并发布。
echo Enter a character read n printf "%d" $n;
错误-: ./ascii.sh: line 3: printf: a: invalid number
您需要在前面加上一个单引号$n:
$n
echo Enter a character read n printf "%d" \'$n
您还可以摆脱echo:
echo
read -p 'Enter a character: ' n printf "%d" \'$n