quoting

Do I need to quote command substitutions?

久未见 提交于 2019-11-28 11:35:01
According to the Google Shell Style Guide , I should: Always quote strings containing variables, command substitutions, spaces or shell meta characters, unless careful unquoted expansion is required. Maybe I am misinterpreting what they mean by "command substitutions", but I am wondering if there is any need to use quotes in the following example: VAR="$(echo foo bar)" Gilles $(echo foo bar) is indeed a command substitution. In this specific example, you don't need double quotes because a variable assignment creates a “double quote context” for its right-hand side, so VAR=$(…) is equivalent to

Double quotes inside quotes in bash

耗尽温柔 提交于 2019-11-28 11:27:05
问题 I need pass $var_path to bash script inside single quotes and then get commnd executed on remote host. I know that single quotes do not allow passing variables, so tried double quoting, but getting error in sed. Assume this happens because its template uses " as well. var="Test text" var_path="/etc/file.txt" echo "$var"|ssh root@$host 'cat - > /tmp/test.tmp && sed -n "/]/{:a;n;/}/b;p;ba}" $var_path > /tmp/new.conf.tmp' so with "" var="Test text" var_path="/etc/file.txt" echo "$var"|ssh root@

How do I pass on script arguments that contain quotes/spaces?

狂风中的少年 提交于 2019-11-28 08:10:19
I'm trying to write a script notify-finish that can be prepended to any command. When done, it will run the command given by the arguments following, then email the user when the command is complete. Here's what I have: PROG=$1 # Run command given by arguments $@ ECODE=$? echo -e "Subject: `hostname`: $PROG finished\r\nTo: <$USER>\r\n\r\nExited with $ECODE\r\n" | sendmail $USER This works most of the time, but when arguments contain spaces, the quoting is stripped off. Working example: notify-finished rsync -avz source/ user@remote:dest/ Failing example: notify-finished rsync -avz -e 'ssh -c

Bash: How to use operator parameter expansion ${parameter@operator}?

北城以北 提交于 2019-11-28 07:21:47
问题 I've googled and tried so many things and never could get anything to work with ${parameter@operator}. All I find is more links to the same documentation. So I think a proper answer with practical examples would be very helpful to its understanding. The documentation says: ${parameter@operator} The expansion is either a transformation of the value of parameter or information about parameter itself, depending on the value of operator. Each operator is a single letter: Q The expansion is a

How to escape the single quote character in an ssh / remote bash command?

早过忘川 提交于 2019-11-28 06:51:57
I'm building a small set of scripts for remotely starting, stopping and checking the status of a process. The stop of these scripts should look for a process and kill it. Therefore I do: ssh deploy@hera 'kill -9 `ps -ef | grep MapReduceNode | grep -v "grep" | awk -F " " '{print $2}' | head -n 1`' The problem here is that the awk tokenization step needs single quotes and these clash with the single quote utilized for executing the remote command via ssh. How can these single quotes be escaped? Use ssh deploy@hera 'kill -9 `ps -ef | grep MapReduceNode | grep -v "grep" | awk -F " " '"'"'{print $2

What difference does ssh command quoting make?

﹥>﹥吖頭↗ 提交于 2019-11-28 06:08:45
问题 How is it that these commands result in different output? ⋊> ssh host bash -c 'cd /tmp; pwd' /home/manu ⋊> ssh host "bash -c 'cd /tmp; pwd'" /tmp An answer to a similar question here states that: The trailing arguments are combined into a single string which is passed to as an argument to the -c option of your login shell on the remote machine. In case of an * I can understand this, but what part would be evaluated locally in this example? Also, an -- before the bash command doesn't help. 回答1

What Vim command(s) can be used to quote/unquote words?

一世执手 提交于 2019-11-28 02:38:50
How can I quickly quote/unquote words and change quoting (e.g. from ' to " ) in Vim? I know about the surround.vim plugin, but I would like to use just Vim. surround.vim is going to be your easiest answer. If you are truly set against using it, here are some examples for what you can do. Not necessarily the most efficient, but that's why surround.vim was written. Quote a word, using single quotes ciw'Ctrl+r"' ciw - Delete the word the cursor is on, and end up in insert mode. ' - add the first quote. Ctrl+r" - Insert the contents of the " register, aka the last yank/delete. ' - add the closing

Strange Lisp Quoting scenario - Graham's On Lisp, page 37

早过忘川 提交于 2019-11-27 23:32:54
问题 I'm working my way through Graham's book "On Lisp" and can't understand the following example at page 37: If we define exclaim so that its return value incorporates a quoted list, (defun exclaim (expression) (append expression ’(oh my))) > (exclaim ’(lions and tigers and bears)) (LIONS AND TIGERS AND BEARS OH MY) > (nconc * ’(goodness)) (LIONS AND TIGERS AND BEARS OH MY GOODNESS) could alter the list within the function: > (exclaim ’(fixnums and bignums and floats)) (FIXNUMS AND BIGNUMS AND

quoting constants in php: “this is a MY_CONSTANT”

荒凉一梦 提交于 2019-11-27 23:31:16
I want to use a constant in php, but i also want to put it inside double quotes like a variable. Is this at all possible? define("TESTER", "World!"); echo "Hello, TESTER"; obviously outputs "Hello, TESTER", but what I really want is something like: $tester = "World!"; echo "Hello, $tester"; ouputs "Hello, World!". Sorry, that's not the way constants in PHP work. You can put variables in double quotes and heredocs but not constants. I recomend you to use concatenation because: When you use a variable into a double quotes string your visibility is not good; When you use a double quotes string

csv writer in Python with custom quoting

谁说我不能喝 提交于 2019-11-27 17:49:03
问题 I'm looking for a way to define custom quoting with csv.writer in Python. There are 4 built-in ways to qoute values: csv.QUOTE_ALL, csv.QUOTE_MINIMAL, csv.QUOTE_NONNUMERIC, csv.QUOTE_NONE However I need a quoting mechanism which will emulate Postgres' FORCE QUOTE * , i.e. it will quote all non-None values. With csv.QUOTE_ALL Python will turn None into '' but I would like to have empty string instead. Is it possible to do that with built-in csv module ( I'm not interested in hacks, I'm already