Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash escape special characters in variable

# Use Shell Parameter Expansion:
foo_esc="${foo@Q}"
Comment

bash escape all special characters

#You can use the %q format specifier with printf to take care of the variable escaping for you:
#source: https://serverfault.com/questions/625641/how-can-i-run-arbitrarily-complex-command-using-sudo-over-ssh

cmd="ls -al"
printf -v cmd_str '%q' "$cmd"
ssh user@host "bash -c $cmd_str"
Comment

escape characters in bash

use "" to use the literal value of the next character (except newline)
Comment

PREVIOUS NEXT
Code Example
Shell :: git clone without project folder 
Shell :: mac ssh download folder 
Shell :: dir in file txt 
Shell :: how to use scp 
Shell :: To add repo from github in linux 
Shell :: git update another branch 
Shell :: flask make how public 
Shell :: docker start container detached 
Shell :: force push to remote branch 
Shell :: rabbitmqctl 
Shell :: how to edit a file in terminal windows 
Shell :: git basics 
Shell :: grep substring 
Shell :: linux bash search history 
Shell :: bash if else if 
Shell :: curl command parameters 
Shell :: angular extract i18n 
Shell :: ssh set owner 
Shell :: sudo apt install rosecore 
Shell :: Push to an existing repository form command line 
Shell :: xp_cmdshell bcp 
Shell :: run specific logrotate 
Shell :: ubuntu list compillers 
Shell :: xsl fo when else 
Shell :: thinderbird download linux mint 
Shell :: how to install mx package manager 
Shell :: store all terminal output in a file 
Shell :: workspace switch shortcur Gnome 
Shell :: sudo systemctl enable journalbeat sudo systemctl start journalbeat 
Shell :: cron every 5 minutes offset 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =