Pop-Up Thingie
Sidebar
>>> Magnum BBS <<<
Home
Forum
Files
Dark
Log in
Username
Password
Sidebar
Forum
Usenet
COMP.UNIX.SHELL
How do I escape a string that contains both single and double quotes?
From
Ottavio Caruso
@21:1/5 to
All
on Thu Mar 17 10:16:21 2022
Hi,
I have a function that checks the occurrence of characters in a string:
cw-sort ()
{
echo $1 | sed 's/./&\n/g' | sort | uniq -ic | sort -rn
}
This is all fine and dandy as long as there are no funny characters:
$ cw-sort uyrwqoequwyroqiuwey8378429537uriewr
4 w
4 u
4 r
3 y
3 q
3 e
2 o
2 i
2 8
2 7
2 3
1 9
1 5
1 4
1 2
1
When you throw single quotes in the mix, you have to escape them in
double quotes:
$ cw-sort "uyrwqoequwyroqiuwey83'''''78429537uriewr"
5 '
4 w
4 u
4 r
3 y
3 q
3 e
2 o
2 i
2 8
2 7
2 3
1 9
1 5
1 4
1 2
1
Likewise, if you throw double quotes in the mix, you have to escape them
in single quotes:
$ cw-sort 'uyrwqoequwyroqiuwey83"""""""""""78429537uriewr'
11 "
4 w
4 u
4 r
3 y
3 q
3 e
2 o
2 i
2 8
2 7
2 3
1 9
1 5
1 4
1 2
1
But what if you have both single and double quotes?
$ cw-sort 'uyrwqoequwyroqiuwey83""""'''''78429537uriewr'
$
$ cw-sort "uyrwqoequwyroqiuwey83""""'''''78429537uriewr"
5 '
4 w
4 u
4 r
3 y
3 q
3 e
2 o
2 i
2 8
2 7
2 3
1 9
1 5
1 4
1 2
1
Wrapping the string in single quotes, makes the function choke. Wrapping
the string in double quotes makes the double quotes disappear from the
count.
How do I get out of this?
--
Ottavio Caruso
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
Who's Online
Recent Visitors
Rixter
Mon Sep 14 12:01:34 2026
from
Madison, Nc
via
Telnet
Bob Worm
Mon Sep 14 08:34:31 2026
from
Wales, Uk
via
Telnet
Retrojimmyx
Mon Sep 14 00:27:04 2026
from
Derbyshire
via
Telnet
Rixter
Mon Sep 14 00:01:35 2026
from
Madison, Nc
via
Telnet
Sam Shaxted
Sun Sep 13 14:48:09 2026
from
Sittingbourne, Kent
via
SSH
Furryboy
Sun Sep 13 13:32:38 2026
from
Romania, Galati
via
SSH
Bob Worm
Sun Sep 13 13:31:58 2026
from
Wales, Uk
via
Telnet
Rixter
Sun Sep 13 12:01:35 2026
from
Madison, Nc
via
Telnet
System Info
Sysop:
Keyop
Location:
Huddersfield, West Yorkshire, UK
Users:
764
Nodes:
16 (
2
/
14
)
Uptime:
33:10:18
Calls:
12,756
Calls today:
4
Files:
15,359
Messages:
6,556,836