Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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/4/unix/3.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_Unix_Shell - Fatal编程技术网

Bash shell编程中如何从键盘输入数据

Bash shell编程中如何从键盘输入数据,bash,unix,shell,Bash,Unix,Shell,在shell编程中如何从键盘输入数据 一些类似于c中scanf的命令可以使用“read”: 以及,执行脚本: $ sh ./test.sh enter the value : 145 The value is : 145 你可以用“猫” 可以使用cat语句完成输入 #!/bin/sh name=$(cat) echo "Welcome" "$name" 如果我们将输入作为Bash。然后输出: Welcome Bash 请注意,根据您的外壳,情况可能会有所不同。请重新

在shell编程中如何从键盘输入数据

一些类似于c中scanf的命令可以使用“
read
”:

以及,执行脚本:

$ sh ./test.sh
enter the value : 145
The value is : 145
你可以用“猫”

可以使用cat语句完成输入

    #!/bin/sh
    name=$(cat)
    echo "Welcome" "$name"
如果我们将输入作为Bash。然后输出:

Welcome Bash

请注意,根据您的外壳,情况可能会有所不同。请重新标记以说明哪个shell:bash,korn,cshBash:“read”有一些有用的选项,例如,-p指定提示:read-p'输入值:'my_var请参阅“help read”了解更多信息。
-s
选项对于我们不希望显示的密码条目表现良好,-s选项会导致来自终端的输入不被回显。
Welcome Bash