English 中文(简体)
我怎样才能在巴什的单一引文中找到一个字句?
原标题:How can I escape a single quote in a single-quote string in Bash?

I want to display a string in Bash like this:

I m a student

当然,你可以这样做:

echo "I m a student"

但是,我如何在使用插图上的单一引语时做到这一点?

最佳回答
echo  I m a student 

不可行。 但以下工作:

echo $ I m a student 

ash印的手页:

A single quote may not occur between single quotes, even when preceded by a backslash.
....
Words of the form $ string are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.

问题回答

格伦·杰克曼提到的“简单”解决办法实际上应列为最高一级的答案。 在某些局势中,它运作良好,实际上是美丽的。

 I " " m a student 

This ends the single quoted string after I then immediately starts a double quoted string containing a single quote and then starts another single quoted string. Bash then concatenates all contiguous strings into one.

美丽!

以下例子有其作用,因为从技术上讲,从两个单一引用的论据之间就出现了“>。

echo  I   m a student 

另一种工作方式是使用<条码>f, 取而代之<条码>。

printf  Ix27m a student!
 




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签