Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 我如何才能让阅读不再';在Shell脚本中显示它的价值?_Bash_Shell - Fatal编程技术网

Bash 我如何才能让阅读不再';在Shell脚本中显示它的价值?

Bash 我如何才能让阅读不再';在Shell脚本中显示它的价值?,bash,shell,Bash,Shell,大家好,我正在使用Ubuntu11,我正在用它编写一些shell脚本。 我现在面临的唯一问题是“阅读”显示它的价值,我不知道它是如何发生在我身上的,因为这是第一次。当我使用“阅读”时,我能看到它的价值!!!! 这是我的密码: #!/bin/bash echo -n "Which file you want 2 store: " read fname echo -n "Do u want 2 delete file $fname in its current location? [Y\N]: "

大家好,我正在使用Ubuntu11,我正在用它编写一些shell脚本。 我现在面临的唯一问题是“阅读”显示它的价值,我不知道它是如何发生在我身上的,因为这是第一次。当我使用“阅读”时,我能看到它的价值!!!! 这是我的密码:

#!/bin/bash

echo -n "Which file you want 2 store: "
read fname
echo -n "Do u want 2 delete file $fname in its current location? [Y\N]: "
read ansr

sudo tar -c -v -f The_Store.tar $fname
sudo chmod 700 The_Store.tar

if [ "$ansr" = "Y" ]; then
rm $fname
fi

echo "Congrats, ur file been stored"
“fname”的值在用户回答以下问题后显示:是否要在当前位置删除文件$fname?。谁能帮我一下吗


我所要做的就是隐藏“fname”的值。

来自
bash
手册部分关于
read

-s静音模式。如果输入来自终端,则不会回显字符


如果您的shell的
read
buildin不支持
-s
选项,您也可以使用
stty
命令:

echo "Which file you want 2 store: "
stty -echo
read fname
stty echo

echo "Do u want 2 delete file $fname in its current location? [Y\N]: "
stty -echo
read ansr
stty echo

两种解决方案都不起作用。请告诉我们您的bash版本、操作系统和版本。通过使用-s或stty版本,您是否收到任何错误消息?我的操作系统是OSX 10.7,Virtualbox 4.6,Ubuntu和Linux 2.6.38-8-generic-pae。这是什么意思?shell是否可能找不到stty命令,该命令是否已找到,但无法识别其参数,或者只是默默失败?你的操作系统是什么,shell和你使用的终端是什么?我的操作系统是OSX,Virtualbox Ubuntu,Linux 2.6.38-8-generic-PAE,shell查找命令,但是当我写文件名时,我不能用c!!&仍然$fname在Q之后出现!!!尝试将
echo
命令放在第一个
stty
命令之后