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
Bob Worm
Tue Jul 28 16:01:18 2026
from
Wales, Uk
via
Telnet
Rixter
Tue Jul 28 13:42:46 2026
from
Madison, Nc
via
Telnet
Krenn
Tue Jul 28 11:59:57 2026
from
Sydney, Nsw
via
Telnet
Rixter
Tue Jul 28 01:23:48 2026
from
Madison, Nc
via
Telnet
Centurion
Mon Jul 27 22:50:42 2026
from
Berea, Ohio
via
Telnet
Ataricrypt
Mon Jul 27 19:19:17 2026
from
England
via
Telnet
Bob Worm
Mon Jul 27 15:19:55 2026
from
Wales, Uk
via
Telnet
Rixter
Mon Jul 27 13:04:59 2026
from
Madison, Nc
via
Telnet
System Info
Sysop:
Keyop
Location:
Huddersfield, West Yorkshire, UK
Users:
741
Nodes:
16 (
2
/
14
)
Uptime:
51:05:31
Calls:
12,444
Calls today:
4
Files:
15,192
Messages:
6,537,208