echo "Enter message body" body=$(< /dev/stdin) (加上错误检查代码我省略了succintness) 然而,这可能是因为第二次和第三次重定向得到EOF而得到一个空的主体和身体。 我一直试图关闭并重新打开stdin与<& - 和东西,但它似乎没有那样工作。 我甚至尝试使用分隔符作为文件列表,使用“while; read line”循环并...
Read a line from the standard input and split it into fields. 上面是把stdin在command line 用 '<' 重定向到FILENAME中,然后用echo来输出到stdout里面。 下面有几种变化方式,来将他变形一下: 1、可以把上面第11行while read line 改成 cat FILENAME(也可以用绝对路径) | while read line 。这样就不...
Used to exit from the current shell. pwd Display the path of the current working directory. read Read one line from STDIN and assigns it to a variable. popd Removes entries from the directory stack. pushd Add a directory to the directory stack. printf Displays text in a formatted string. ...
从Bash 脚本中的stdin输入 我们还可以从终端或 Bash 脚本中的stdin获取用户输入。我们可以使用内置的 Bash 命令read来读取 Bash 用户输入。 它接受用户的输入并将其分配给一个变量。它只能从 Bash shell 中读取一行。 语法: read<variable> 每个以空格分隔的单词都保存在不同的变量中。
$ cat read.sh #! /bin/bash echo -e "Enter absolute path of the file name you want to read" read file exec <$file # redirects stdin to a file while read line do echo $line done $ ./read.sh Enter absolute path of the file name you want to read /tmp/a while for until ...
从stdin中"读取"一个变量的值, 也就是, 和键盘进行交互, 来取得变量的值. 使用-a参数可以read数组变量,例如 1:#!/bin/bash 2: 3:declare -a colors 4:# 脚本中所有的后续命令都会把变量"colors"看作数组. 5: 6:echo"Enter your favorite colors (separated from each other by a space)." ...
从Bash 脚本中的stdin输入 我们还可以从终端或 Bash 脚本中的stdin获取用户输入。我们可以使用内置的 Bash 命令read来读取 Bash 用户输入。 它接受用户的输入并将其分配给一个变量。它只能从 Bash shell 中读取一行。 语法: read<variable> 每个以空格分隔的单词都保存在不同的变量中。
Read line: STDIN #! /bin/bash while read line do echo $line done < "${1:-/dev/stdin}" ./hello.sh somefile.txt=> print out the file line by line ./hello.sh=> type a line and print a line Output: STDOUT; STDERR not stderr: file2 will be empty ...
# Saves stdin. # stdin replaced by file "data-file" # Reads first line of file "data-file" # Reads second line of file "data-file" exec 6<&0 exec < data-file read a1 read a2 echo echo "Following lines read from file."
Read from stdin, determine the syntax automatically (note, highlighting will only work if the syntax can be determined from the first line of the file, usually through a shebang such as #!/bin/sh)> curl -s https://sh.rustup.rs | bat...