如何在Bash中使用字符串连接变量? [英] How connect variable with a string in Bash?
本文介绍了如何在Bash中使用字符串连接变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写bash脚本,我在bash文件中使用了如下所示的一个变量
I am writing a bash script , I used 1 variable in my bash file like below
list=`/home/ea/students'
我在bash中写了以下链接,但出现错误
I wrote below link in my bash but I got error
cat $list /admin.txt
您知道如何将变量和字符串连接在一起吗?
Do you know how can I connect variable and string together?
推荐答案
首先,您需要在字符串周围使用单引号(''
'),而不是反引号('`')
Firstly you need to use single quotes (''
') around strings, not backticks ('`')
list='/home/ea/students'
要将字符串附加到变量,请执行以下操作:
To append a string to a variable, do the following:
list=${list}/admin.txt
演示:
echo $list
/home/ea/students/admin.txt
这篇关于如何在Bash中使用字符串连接变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文