如何在shell脚本中为变量加上引号

Kus*_*tel 2 shell-script

我的代码如下,

file="test.text"
while IFS= read line
do
        # display $line or do somthing with $line
    x="\'$line\'"
    echo $x
    # sleep 10

done <"$file"
Run Code Online (Sandbox Code Playgroud)

但是,这个给了我以下结果。

\'google.com
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏

jes*_*e_b 5

双引号内的单引号不需要转义字符。双引号已经转义单引号。只需使用:

x="'${line}'"
Run Code Online (Sandbox Code Playgroud)