It's easier if you spread it out a little:
watch -ben5 '
lsof /mnt/unfs &&
ps -o tty= -p "$(lsof -F p0 /mnt/unfs | sed -e "s/p//")" |
xargs -I terms sudo sh -c '\''
printf "\n\33[97;101m%s\33[31;49m%s\33[97;101m%s\33[39;49m\n" \
"GET OUT OF UNFS" " cd ~ " "NOW!" >/dev/terms'\'''
It's pretty difficult for me to understand what's going on here exactly. But if you wanted to put that in an alias, it's pretty simple: you just add another '
. Here's a trick:
alias myalias="$(cat <<\IN
watch -ben5 '
lsof /mnt/unfs &&
ps -o tty= -p "$(lsof -F p0 /mnt/unfs | sed -e "s/p//")" |
xargs -I terms sudo sh -c '\''
printf "\n\33[97;101m%s\33[31;49m%s\33[97;101m%s\33[39;49m\n" \
"GET OUT OF UNFS" " cd ~ " "NOW!" >/dev/terms'\'''
IN
)"
The here-document is another form of shell-quote. And all quotes can be contained within hardquotes except hardquotes. So you can go as many levels deep as you like by finding every occurrence of a hardquote and escaping it. By which I mean turning every '
into '\''
. After you've done so, you can wrap the entire statement in another layer of quotes. And in fact, alias
does this for you:
alias myalias
myalias=' watch -ben5 '\''
lsof /mnt/unfs &&
ps -o tty= -p "$(lsof -F p0 /mnt/unfs | sed -e "s/p//")" |
xargs -I terms sudo sh -c '\''\'\'\''
printf "\n\33[97;101m%s\33[31;49m%s\33[97;101m%s\33[39;49m\n" \
"GET OUT OF UNFS" " cd ~ " "NOW!" >/dev/terms'\''\'\'\'\'
printf "%q" \'whatever\'
and then cut and paste the response. – user3188445 Jul 25 '15 at 00:05