在Bash中,试过这个:
echo -e "hello\nworld"
Run Code Online (Sandbox Code Playgroud)
但它不会仅打印换行符\n.如何让它打印换行符?
我正在使用Ubuntu 11.04.
我有这个多行字符串(包括引号):
abc'asdf"
$(dont-execute-this)
foo"bar"''
Run Code Online (Sandbox Code Playgroud)
如何在Bash中使用heredoc将其分配给变量?
我需要保留换行符.
我不想逃避字符串中的字符,这会很烦人......
我有
var="a b c"
for i in $var
do
p=`echo -e $p'\n'$i`
done
echo $p
Run Code Online (Sandbox Code Playgroud)
我想要打印最后一个回声
a
b
c
Run Code Online (Sandbox Code Playgroud)
请注意,我希望变量p包含换行符.我怎么做?
我在*nix中相当新.有没有办法创建一个屏幕,它将立即执行给定的命令序列(使用自己的参数)?两个小时的谷歌搜索没有产生任何结果 - 也许是因为我无法清楚地说出这个问题.
我希望有类似的东西
screen -dmS new_screen exec "cd /dir && java -version"
Run Code Online (Sandbox Code Playgroud)
我使用的是屏幕v4.00.03和CentOS 5.5(内核版本2.6.18-194.26.1.el5.028stab079.2)
\nshell字符串中不考虑新行
root@toto:~# str="aaa\nbbbb"
root@toto:~# echo $str
aaa\nbbbb
Run Code Online (Sandbox Code Playgroud)
预期结果:
root@toto:~# echo $str
aaa
bbbb
Run Code Online (Sandbox Code Playgroud)
如何在字符串中添加新行?
当我git log用来检查我的提交解释性说明时
1. what I changed
2. blank line
3. why I changed it
Run Code Online (Sandbox Code Playgroud)
在3行不像1. what i changed 2. blank line 3. why i changed只在1行.
如何使用linux mail命令在电子邮件中插入新行?
echo "Hi xxx, would you tell me something?\\n thanks!\\n -xxx" | mail -s "subject" xxx@gmail.com
Run Code Online (Sandbox Code Playgroud)
电子邮件显示文字'\n',而不是换行符,如何解决?
我目前正在编写一个bash测试框架,它需要尽可能的便携.
所以,在某一点上,我必须打印一个前导换行符,然后是一些包含几个扩展变量的文本.这是我用过的解决方案.
echo -e "\n$number_of_specs ${units}, $number_of_specs_failed failed"
Run Code Online (Sandbox Code Playgroud)
这看起来没问题但是我不确定与使用例如打印出来的线相比是多么便携printf?
有什么想法或提示,我可以找到一些参考?
有没有办法让Bash heredoc在heredoc中解释'\n \'?
我在循环中有一个迭代构建的字符串,类似于
for i in word1 word2 word3
do
TMP_VAR=$i
ret="$ret\n$TMP_VAR"
done
Run Code Online (Sandbox Code Playgroud)
然后我想在heredoc中使用创建的字符串:
cat <<EOF > myfile
HEADER
==
$ret
==
TRAILER
EOF
Run Code Online (Sandbox Code Playgroud)
但是我想将"\n"字符解释为换行符,以便输出为
HEADER
==
word1
word2
word3
==
TRAILER
Run Code Online (Sandbox Code Playgroud)
代替
HEADER
==
\nword1\nword2\nword3
==
TRAILER
Run Code Online (Sandbox Code Playgroud)
可能吗?或者我应该以某种方式构建我的初始字符串?
与如何在 sh 的字符串中添加换行符是同样的问题 ? 但在鱼壳里。
在 bash 中我们有:
$'this is line\nthis is another line'
谁产生了预期的结果,但在鱼中这不起作用。
鱼有类似的方法吗?
编辑1:
faho 明智地提到了字面方法:
'this is line
this is another line'
\n但我真的很好奇是否存在像 shell 中那样保留换行符引用的方法。
我想知道是否可以使用这个字符串"this is a line\nthis is another line"来确保鱼将其视为\n换行符而不是文字。