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 pull from another repository 
Shell :: kubectl neat not found 
Shell :: Cargo, the Rust package manager, is not installed or is not on PATH. 
Shell :: kubernetes get deployments 
Shell :: git clone repo with name 
Shell :: powershell merge multiple text files 
Shell :: how to deploy on heroku 
Shell :: ssh without password 
Shell :: how to remove non empty dircetory 
Shell :: body-parser use 
Shell :: Run Google Colab With Local Files 
Shell :: [Errno 13] Permission denied: ubuntu 
Shell :: fetch all git branches 
Shell :: pupeteer install ubuntu 
Shell :: how to uninstall program on ubuntu 
Shell :: gcc 7 install ubuntu 
Shell :: gh create github repo 
Shell :: grep ignore binary file 
Shell :: pip install geoip2 
Shell :: git remove all files in gitignore 
Shell :: git replace local branch with remote 
Shell :: linux uninstall package 
Shell :: refresh gnome shell 
Shell :: varible 
Shell :: ubuntu permission all file in folder 
Shell :: homebrew on mac 
Shell :: install Fdisk 
Shell :: Sublime Text install Ubuntu/Debian 
Shell :: pip 21.0.1 install windows 
Shell :: bash split line and get element 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =