Escape quote in alias
Writing by shivdev on Wednesday, 22 of October , 2014 at 5:25 pm
I wanted to create change the prompt to show the active git branch through an alias.
Changing PS1 as follows would do it as follows:
# Try this in bash to get the git prompt, but how do you alias this?
PS1='[\u@\h \W$(__git_ps1 ” (%s)”)]\$
However I needed to create an alias for it and turns out that if you wanted to escape a single quote ‘ you could do it using the following: ‘”‘”‘
# Note here that the entire aliased string needs to be escaped using a quote
alias ingit=’PS1='”‘”‘[\u@\h \W$(__git_ps1 ” (%s)”)]\$'”‘””
Now I can activate the git prompt that I need through an alias that contains a combination of single and double quotes.
Now !!! I wanted to change the IP Address of my DHCP vm in the /etc/hosts file. (Related sed Article)
# something that works
$ sed -i ” ‘s/^192.168.*vm/192.168.1.12 vm/’ /etc/hosts# i would like to do something like this
$ setvmip 192.168.1.12# so the escaped version is
alias setvmip=’function _setvmip(){ sudo sed -i “” ‘”‘”‘s/^192.168.*vm/'”‘”‘$@'”‘”‘ vm/'”‘”‘ /etc/hosts ; }; _setvmip’
Leave a comment
Category: Linux
- Add this post to
- Del.icio.us -
- Digg -
- -
- Tweet -
-
-
No comments yet.
You must be logged in to post a comment.