Logo

dev-resources.site

for different kinds of informations.

Escape quotes correctly when using psql via docker in bash

Published at
11/18/2024
Categories
bash
quote
escape
shell
Author
zaphoddont
Categories
4 categories in total
bash
open
quote
open
escape
open
shell
open
Author
10 person written this
zaphoddont
open
Escape quotes correctly when using psql via docker in bash
docker compose exec site bash -c 'PGPASSWORD=***** psql -Ufoo -d bar \
  -h example.com -x -c "select qux, date(xyzzy) from tabley \
  where field in(1, 2, 3) and that_time > '"'"'2024-11-18'"'"' \
  order by that_time;"'
Enter fullscreen mode Exit fullscreen mode

Explanation:

'"'"' is the Quoteception operator. When used in the middle of a single quoted string, it:

  • ' Ends the single quoted string
  • " Starts a new double quoted string
  • ' Containing only one single quote
  • " Ends the double quoted string
  • ' Starts the next single quoted string

Or described another way:

echo 'Embedded single quote is here: '"'"' did you see it?'

echo 'Embedded single quote is here: ' \
"'"                                    \
' did you see it?'
Enter fullscreen mode Exit fullscreen mode

Outputs:

Embedded single quote is here:  '  did you see it?
Enter fullscreen mode Exit fullscreen mode
shell Article's
30 articles in total
Favicon
Poor man's parallel in Bash
Favicon
Ergonomic Pyhon Text Piping Solution for Linux Shell with pypyp and uv
Favicon
Become a Bash Scripting Pro in 10 Minutes: A Quick Guide for Beginners
Favicon
Final Bash Script Series Mastering Remote Server Management and Web App Deployment
Favicon
kkTerminal —— A terminal for Web SSH connection
Favicon
The Complete Guide to Bash Commands
Favicon
Navigating TC39 Proposals: From Error Handling to Iterator.range
Favicon
Introducing TheShell: A Game-Changer in LivinGrimoire
Favicon
Pick Files from a List for Git Add and Stash Directly in Your Terminal
Favicon
Start Shell Programming: A Beginner's Guide âš™ [Part-I]
Favicon
Pytest Fish shell autocompletion
Favicon
Discover File Splitter & Merger: A Revolutionary Tool for Managing Large Files
Favicon
🚀 RazzShell v1.0.1 is Here: Plugin Support, Enhanced Job Management, and More! 🌟
Favicon
ps, kill -9 PID
Favicon
\\wsl$
Favicon
Escape quotes correctly when using psql via docker in bash
Favicon
Bash vs. Shell: The Ultimate Comparison
Favicon
Search and Sync Your Shell History With Atuin
Favicon
Building a (somewhat) intelligent agent
Favicon
Environment Management in Bash: Unlocking the Secrets of the Shell
Favicon
3 Must-Know File Permissions and Ownership Commands
Favicon
Ask Git to Show a Method
Favicon
UNIX
Favicon
DEV OPS JOURNEY
Favicon
Unlock the Secrets of Your Command Line with the History Command
Favicon
Mastering Text Processing with Grep, Sed, Awk, Cut, and Sort
Favicon
Shell Special Variables and Execution Environment
Favicon
Spice up Your Terminal With a Todo Reminder Using Starship Prompt and iZiDo Bash Script
Favicon
Introducing RazzShell: A Customizable Unix Shell for Modern CLI Users
Favicon
File Management in Bash : Commands and Examples

Featured ones: