Skip to main content

Questions tagged [quoting]

Strings are typically delimited by quotes, which raises the problem of dealing with strings that include quotes.

8 votes
2 answers
31k views

"grep: Unmatched [" error when using regex

I'm trying to find a pattern similar to this: tail -n 100000 gateway.log | grep -B10 -A10 'Nov 22 11:13:56 Received Packet from [10.50.98.68' Where "11:13:56" could be any time. This is what I came ...
2 votes
3 answers
4k views

Variable expansion inside parentheses and quotes

In the script below, I can't seem to make $var1 expand in the second statement. I've tried $var1, ${var1}, echo $var1 and '$var1'. It is inside a few sets of quotes and parentheses which I guess is ...
1 vote
1 answer
3k views

How do I quote square brackets in Ansible variable value for regexp parameter?

I use the ansible.builtin.lineinfile module to modify a PHP-FPM pool configuration file. How should I quote the square brackets (annot.: or other special characters) in a value of a variable for the ...
5 votes
2 answers
601 views

Bash reads quotes inside a variable as text, not quotes? Is "Implicit quoting" a thing in Bash?

I've got a bash script that cleans up the mail queue periodically. For Reasons, we've elected to delete any email to @mms.att.net and other email2SMS gateways that are over 9 hours in the queue and ...
28 votes
8 answers
40k views

awk print apostrophe/single quote

Can't figure out how to escape everything while using awk. I need to enclose each input string with with single quotes, e.g. input string1 string2 string3 output 'string1' 'string2' 'string3' Been ...
6 votes
1 answer
2k views

How do I tell GNU Parallel to not quote the replacement string

GNU Parallel quotes replacement strings by default so that they are not expanded by the shell. But in certain cases you really want the replacement string to be interpreted by the shell. E.g. $ cat ...
29 votes
2 answers
6k views

How to execute an arbitrary simple command over ssh without knowing the login shell of the remote user?

ssh has an annoying feature in that when you run: ssh user@host cmd and "here's" "one arg" Instead of running that cmd with its arguments on host, it concatenates that cmd and ...
148 votes
11 answers
55k views

What is the difference between $* and $@?

Consider the following code: foo () { echo $* } bar () { echo $@ } foo 1 2 3 4 bar 1 2 3 4 It outputs: 1 2 3 4 1 2 3 4 I am using Ksh88, but I am interested in other common ...
214 votes
6 answers
198k views

How can I execute `date` inside of a crontab job?

I want to create a log file for a cron script that has the current hour in the log file name. This is the command I tried to use: 0 * * * * echo hello >> ~/cron-logs/hourly/test`date "+%d"`.log ...
7 votes
2 answers
13k views

How to render variables without quotes in bash script?

The following script: $ cat runme01.sh #!/bin/bash A=myval B=$A/{fix} C=$A/fix set -xT echo $B echo $C prints the following if ran: $ ./runme01.sh + echo 'myval/{fix}' myval/{fix} + echo myval/...
217 votes
3 answers
105k views

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
0 votes
1 answer
233 views

Unable to resolve parameter inside json

I'm using a curl command inside a script (edm.ksh) to retrieve some data from an API, it requires a password in a JSON like {"password":"myPassword"}. Now, myPassword is not ...
0 votes
1 answer
153 views

Bash variable quoting in a function

I've defined a short helper function in a bash script. For legibility, I'd like to replace the boilerplate headers with a variable declared outside the function. I've tried quoting the declaration ...
10 votes
4 answers
19k views

Properly escaping output from pipe in xargs

Example: % touch -- safe-name -name-with-dash-prefix "name with space" \ 'name-with-double-quote"' "name-with-single-quote'" \ 'name-with-backslash\' xargs can't seem to handle double quotes:...
7 votes
2 answers
1k views

Echoing "!" inside a string does some weird things [duplicate]

If I type in this: echo "Hello, World!" I don't know the name of it, but it prompts me for the next line. You know the PS2 thing. Or if you type echo \ and press Enter. Why? Well I know ...

15 30 50 per page
1 2 3
4
5
72