我试图将一个期望的脚本回显到一个文件中,这样我就可以动态执行它。
这是我到目前为止所做的:
#!/bin/bash
echo '#!/usr/bin/expect -f' > expect_file
echo 'expect "\[RETURN\]" {send "\r"}' >> expect_file
将产生一个包含以下内容的文件:
#!/usr/bin/expect -f
"}pect "\[RETURN\]" {send "
如果我尝试使用echo并转义引号:
#!/bin/bash
echo '#!/usr/bin/expect -f' > expect_file
echo "expect \"\[RETURN\]\" {send \"\r\"}" >> expect_file
cat expect_file
exit 0
expect命令和部分行不会被回显
#!/usr/bin/expect -f
"}pect "\[RETURN\]" {send "
如何在我的bash脚本中自行回显代码行或将代码行放入文件中?
#!/usr/bin/expect -f
expect "\[RETURN\]" {send "\r"}
expect ":" {send "q"}
expect "otherwise:" {send "y\r"}
expect eof {exit}
答案 0 :(得分:2)
不要使用echo。使用cat:
cat << 'EOF' > expect_file
#!/usr/bin/expect -f
expect "\[RETURN\]" {send "\r"}
expect ":" {send "q"}
expect "otherwise:" {send "y\r"}
expect eof {exit}
EOF
答案 1 :(得分:1)
使用echo
gst-launch-1.0 -v filesrc location=/home/user/somevideo.mp4 ! qtdemux ! ffdec_mpeg4 ! autovideosink
或强>
#!/bin/bash
echo -e '#!/usr/bin/expect -f\nexpect "\\[RETURN\\]" {send "\\r"}\nexpect ":" {send "q"}\nexpect "otherwise:" {send "y\\r"}\nexpect eof {exit}' > expect_file
或强>
#!/bin/bash
echo '#!/usr/bin/expect -f
expect "\[RETURN\]" {send "\r"}
expect ":" {send "q"}
expect "otherwise:" {send "y\r"}
expect eof {exit}' > expect_file