Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #167659
| From | <tomas@tuxteam.de> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: bash Shell - escapes |
| Date | 2016-05-10 12:20 +0200 |
| Message-ID | <rxcVI-yd-21@gated-at.bofh.it> (permalink) |
| References | <rxcj0-8b4-13@gated-at.bofh.it> <rxcj1-8b4-25@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, May 10, 2016 at 11:20:23AM +0200, Die Optimisten wrote: > On 2016-05-10 11:18, Die Optimisten wrote: > >Hi, > > > >How can I escape a ' inside '...' > >e.g. perl -e 'print '$ and a' ' # I don't want to use " The short answer is... you can't. Quoting from the bash man page: "Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash" The long answer is... this woldn't be a shell if there were no useful workarounds. The trick in this situation is just to break up the string. Be aware that to a shell, everything is text, so foo, "foo" and 'foo' are all (in some way) equivalent. This would work: perl -e 'print '"'"'$ and a'"'"' ' # I don't want to use " That is, you glue your string out of several parts, here separated by spaces; only the embedded ' are quoted by "": 'print ' "'" '$ and a' "'" ' ' Of course, in practice you wouldn't do that blind transform, but optimize it a bit, e.g.: "print '"'$'" and ax ' " I.e. just use the '' where you need 'em Then, you can escape the $ whithin the "" with a \ Lots of ways, use whatever is most readable. hth - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlcxtVcACgkQBcgs9XrR2kZmlgCffAw1D1VN5+S6M9QlMtzb+egm 9FcAn1VzNSS8Y0R+APMmc8r0fKUkIeV8 =F9uz -----END PGP SIGNATURE-----
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Shell - escapes Die Optimisten <inform@die-optimisten.net> - 2016-05-10 11:40 +0200
bash Shell - escapes Die Optimisten <inform@die-optimisten.net> - 2016-05-10 11:40 +0200
Re: bash Shell - escapes <tomas@tuxteam.de> - 2016-05-10 12:20 +0200
Re: Shell - escapes "Thomas Schmitt" <scdbackup@gmx.net> - 2016-05-10 13:10 +0200
Re: Shell - escapes <tomas@tuxteam.de> - 2016-05-10 13:30 +0200
Re: Shell - escapes Mark Fletcher <mark27q1@gmail.com> - 2016-05-10 12:10 +0200
Re: Shell - escapes "Thomas Schmitt" <scdbackup@gmx.net> - 2016-05-10 12:50 +0200
Re: Shell - escapes Die Optimisten <inform@die-optimisten.net> - 2016-05-10 14:20 +0200
Re: Shell - escapes <tomas@tuxteam.de> - 2016-05-10 14:30 +0200
Re: Shell - escapes Mark Fletcher <mark27q1@gmail.com> - 2016-05-10 15:20 +0200
Re: Shell - escapes David Wright <deblis@lionunicorn.co.uk> - 2016-05-10 16:00 +0200
Re: Shell - escapes Mart van de Wege <mvdwege@gmail.com> - 2016-05-12 10:10 +0200
Re: Shell - escapes tomas@tuxteam.de - 2016-05-10 15:30 +0200
Re: Shell - escapes "Thomas Schmitt" <scdbackup@gmx.net> - 2016-05-10 16:20 +0200
Re: Shell - escapes David Wright <deblis@lionunicorn.co.uk> - 2016-05-10 16:30 +0200
Re: Shell - escapes "Thomas Schmitt" <scdbackup@gmx.net> - 2016-05-10 16:50 +0200
Re: Shell - escapes <tomas@tuxteam.de> - 2016-05-10 16:40 +0200
Re: Shell - escapes shawn wilson <ag4ve.us@gmail.com> - 2016-05-10 12:20 +0200
Re: Shell - escapes Frédéric Marchal <frederic.marchal@wowtechnology.com> - 2016-05-10 12:30 +0200
Re: Shell - escapes Andy Smith <andy@strugglers.net> - 2016-05-10 15:40 +0200
Re: Shell - escapes <tomas@tuxteam.de> - 2016-05-10 16:00 +0200
Re: Shell - escapes David Christensen <dpchrist@holgerdanske.com> - 2016-05-11 05:50 +0200
csiph-web