[英]How to crete a TSV file using Bash that takes as input some shell variables?
[英]How to write a file with some variables in bash shell?
我試圖通過使用sh文件將變量打印到我的文件,但它不起作用。 這是非常簡單的代碼。 我該如何解決? 而且我不明白。 該腳本按照我的預期在命令中工作。 但是當我將腳本移動到sh
文件時,它顯示了完全不同的結果。
#! /bin/bash
var=12345
echo -e "first sentence
second sentence
$var:$var th sentence
"
我期望
first sentence
second sentence
12345:12345 th sentence
但它告訴我
first sentence
second sentence
th sentence
您的代碼是正確且有效的。
~# bash s.sh
first sentence
second sentence
12345:12345 th sentence
對於多行輸出而不是使用echo
的唯一建議是使用heredoc 。 只要您不單引'EOF'
就會發生正常的變量擴展,例如
#!/bin/bash
var=12345
cat << EOF
first sentence
second sentence
$var:$var th sentence
EOF
示例使用/輸出
$ bash heredoc.sh
first sentence
second sentence
12345:12345 th sentence
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.