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 :: linux run command on ssh connected 
Shell :: fslmaths addition 
Shell :: sonarcube exclude rule via powershell 
Shell :: install modules mu 
Shell :: slurm job specify output directory 
Shell :: Terabyte 
Shell :: sed interst lines to a file 
Shell :: how to filter output to readable characters Linux 
Shell :: how to use find and -regex flag together 
Shell :: mining from cli 
Shell :: shell script backup distant 
Shell :: termbin 
Shell :: pycharm ubuntu freeze keyboard 
Shell :: copy file from windows to linux permission denied wsl 
Shell :: how to delete tempory folder in hpc bash 
Shell :: kontiki cli 
Shell :: running geoserver from a different port ubuntu 
Shell :: git deploy to cpane in .cpanel.yml 
Shell :: cpanel install jpegoptim 
Shell :: iterm full screen cmd 
Shell :: flasky fake 
Shell :: grub file path 
Shell :: how to test a 3rd party python library across multiple environments 
Shell :: macbook tilbud 
Shell :: remove deb repository 
Shell :: join 2 files linux 
Shell :: command to start terminal linux 
Shell :: libopusfile.so.0 terminal download 
Shell :: bash: cd: too many arguments 
Shell :: ostcss-js@4.0.0: The engine "node" tailwindcss 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =