在shell编程中打印双引号 [英] print double quotes in shell programming

查看:314
本文介绍了在shell编程中打印双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在shell编程中使用echo语句打印双引号.

I want to print double quotes using echo statement in shell programming.

示例:

echo "$1,$2,$3,$4";

打印xyz,123,abc,pqrs

如何打印"xyz","123","abc","pqrs";

我曾尝试在echo语句中放置双引号,但未将其打印出来.

I had tried to place double quotes in echo statement but its not being printed.

推荐答案

您只需要引用它们:

echo "\"$1\",\"$2\",\"$3\",\"$4\""

此处:

用双引号(')引起来的字符会保留原义 引号中所有字符的值,"$"除外, ‘`’,‘\’,以及启用历史记录扩展功能的‘!’.那些角色 "$"和`"在双引号中保留其特殊含义(请参见 外壳扩展).反斜杠仅在以下情况下保留其特殊含义: 后跟以下字符之一:"$",`",","\"或 新队.在双引号中,反斜杠后跟一个 这些字符将被删除.反斜杠前面的字符不带 保留特殊含义.可能会用双引号引起来 在双引号内加上反斜杠.如果启用, 除非出现!",否则将执行历史记录扩展 引号使用反斜杠转义. !"前的反斜杠 不会被删除.

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed.

特殊参数"*"和"@"在双精度时具有特殊含义 引号(请参见Shell参数扩展).

The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see Shell Parameter Expansion).

这篇关于在shell编程中打印双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆