Questions tagged [quoting]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
47 views

how to write function with nested commands [duplicate]

I'm trying to write a find and cd function like so: findcd () { cd "$(dirname "$(find '$1' -type '$2' -name '$3')")" } to be called like so: find . f [FILE_NAME] But it's ...
Mathew's user avatar
  • 125
0 votes
1 answer
82 views

Run `git commit -m` with single quotes in zsh

I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
Justin Breen's user avatar
5 votes
2 answers
572 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 ...
Criggie's user avatar
  • 1,781
0 votes
1 answer
136 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 ...
Pratik Khobragade's user avatar
7 votes
2 answers
847 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 ...
Pixelbog's user avatar
  • 540
0 votes
1 answer
41 views

Using a variable in between ' 's

I have a bash script with a line that was originally this convert '%d.jpg[1-300]' combined.pdf Uses convert from Imagemagick to strap a load of sequentially numbered jpgs in to a PDF. I've written a ...
Big_James's user avatar
0 votes
0 answers
31 views

How to escape command line to be able to send it by `ssh` to remote host in all cases?

I am composing command line for ssh with the following (Python) code: def instrument(self, cmd: str) -> str: return "ssh -A %s" % (cmd) and this of course failing in some cases, for ...
Dims's user avatar
  • 3,195
0 votes
2 answers
120 views

Why is echo "\*" the same as echo "\\*"

Title. echo "\*" has the exact same output as echo "\\*", \*. I am using GNU bash 5.2.15. I expected echo "\\*" to output \*, but I do not know why echo "\*" ...
Christopher Lee's user avatar
0 votes
2 answers
238 views

Choose columns with sort and cut in a csv with a comma delimiter ',' ignoring data on quotes with comma "text,text"

I am parsing a huge csv file with rows and columns with different parameters. However, some fields contain large descriptions within quotes that contain commas. How can I choose columns with sort and ...
infinity's user avatar
1 vote
3 answers
155 views

Removing directories with spaces in their directory paths

I'm on macOS. I have many directories at paths that looks like this: ./FirstName SecondName/A Multi Word Title/Contents/Index/files I want to remove ALL the Index directories and their contents. I ...
rbpeirce's user avatar
0 votes
2 answers
109 views

Show quotes with echo inside bash -c

I am trying to echo I say "Hello, World!" with bash -c. This is (some of) what I have tried: $ bash -c "echo I say \"Hello, World"'!'"\"" $ bash -c "echo I ...
Liviu's user avatar
  • 105
7 votes
3 answers
617 views

Is it possible to print a command so that the output can be parsed to create the same command?

The question may sound quite complicated, but in fact it is not! Consider: % f() { echo "$@"; } % f a a % f cmd -o"value with space" cmd -ovalue with space % f cmd -ovalue with ...
U. Windl's user avatar
  • 1,104
3 votes
1 answer
222 views

Problem with single quote in Bash [duplicate]

I have a sh script for initializing dzen2, and I want to use Source Code Pro font to use there. Here's the code... param="-p -dock -fn 'Source Code Pro-10'" # the generated_output function ...
manungsa's user avatar
  • 125
1 vote
1 answer
57 views

Why does enclosing a command in double quotes affect aliases?

I have an alias rm='/bin/rm -i' and I know that if I type "rm" filename in the command line, the alias will be ignored somehow and the normal rm command without the -i flag will be called, ...
BrassPandaSax's user avatar
1 vote
1 answer
2k 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 ...
togo's user avatar
  • 13
4 votes
2 answers
424 views

How to print a double quote in POSIX scripting?

So far, I've been using "\"" to print a double quote: $ x="abc def" $ echo "x=\"$x\"" x="abc def" However, it seems like that behavior is ...
finefoot's user avatar
  • 2,980
3 votes
1 answer
396 views

Why is "${1-"$var"}" (option 6 down below) not mentioned in POSIX?

The only reference I could find in the spec is this: It would be desirable to include the statement "The characters from an enclosed "${" to the matching '}' shall not be affected by ...
QuartzCristal's user avatar
2 votes
1 answer
313 views

rsync does not exclude specified directory starting with a hash character (#)

I am trying to exclude the #recycle directory with rsync: $ rsync -Hauv -h -P --exclude '#recycle/' --exclude @eaDir/ --exclude '.DS_Store*' --exclude desktop.ini user1@src_server:/volume2/...
SebMa's user avatar
  • 1,991
6 votes
1 answer
2k views

Getting jq error when using variable in command line

I am using jq to get the tag_name index with the script: curl \ https://api.github.com/repos/checkstyle/checkstyle/releases \ -H "Authorization: token $GITHUB_TOKEN" \ -o /var/tmp/cs-...
Rahul Khinchi's user avatar
2 votes
1 answer
104 views

Any shell where expansions are turned off without escaping or quoting?

Say, with zsh one can prefix a command with noglob to "turn off filename generation (globbing)". I'm looking for a shell where similar approach can be used to disable not only globbing but ...
poige's user avatar
  • 6,195
7 votes
3 answers
2k views

How to use jq to return information to the shell, taking whitespace into account?

Given this file: $ cat fruits.json [ { "name": "apple" }, { "name": "banana\nfofanna" }, { "name": "my kiwi" } ] how can one use jq ...
jrw32982's user avatar
  • 704
0 votes
1 answer
39 views

How Can I Interpret Quoted Wildcards

I am writing a shell script and I need to interpret quoted wildcards. "R Programming*" I do not want the * asterisk to be taken literally. I want it to be interpreted as a wildcard. "R ...
Amarakon's user avatar
  • 291
8 votes
1 answer
3k views

What are curly quotes and can I use them in my code?

Somehow curly quotes got into my code and I'm getting unexpected behavior #!/bin/sh if [ foo = ‘foo’ ]; then echo yes else echo no fi I would expect this to echo yes but instead it echoes no.
jesse_b's user avatar
  • 36k
2 votes
1 answer
550 views

How to properly use quotes for a bash function?

I am trying to define the following bash function in my .bashrc file: function myfind() { find $1 -not -path venv -not -path .tox -name "$2" | xargs grep -n "$3" } which is ...
Alex's user avatar
  • 5,624
0 votes
2 answers
5k views

unexpected EOF while looking for matching `''

I have created a script to export CSV data to mysql table. #!/bin/bash cd /data/NEW for f in User* do mysql --user="root" --password="user@123" -e "LOAD DATA LOCAL ...
edublog's user avatar
  • 73
3 votes
1 answer
210 views

Recursively renaming apostrophs ' in filenames (Bash)

Need to remove apostrophes from files. I have tried several approaches, also from Stackexchange. I am on a Synology NAS, so I don't have Python, or Perl and furthermore I have to exclude certain ...
Gary Czychi's user avatar
2 votes
2 answers
115 views

Test fails (correctly) on command line, but succeeds (incorrectly) in script

For the sake of this question, assume that the glob /a/b/c/* produces no matches. This means that the following test should fail (in other words, it should produce a non-zero $?): [[ -n /a/b/c/*(#qN) ]...
kjo's user avatar
  • 14.8k
2 votes
1 answer
1k views

pass long html string as argument to bash script (Filename too long)

I am passing an html string as an input to a bash script: Script.py def bash(commandStr): subprocess.Popen(commandStr, shell=True, executable="/bin/bash") def sendmail(subject, to, ...
Leftover Salad's user avatar
2 votes
2 answers
458 views

Escape variable for zsh's `print -P`

I was looking for a way to escape a variable containing format specifiers and special characters like quotes, backslashes and line breaks so that when passing it to print -P it'll print out literally. ...
BrainStone's user avatar
  • 3,544
2 votes
1 answer
47 views

Why isn't the `else` arm executed in this Bash script (for loop through an array)?

The following code is meant to look for subdirectories in ~/Downloads. I run it with . ./script.sh. It will find them even when the user submits an incomplete name. #!/usr/bin/bash echo -e "\...
John Smith's user avatar
0 votes
1 answer
41 views

Why "$(findmnt | grep "\""proc"\"" | head -n 1)" is zero-length? (what is incorrect with escaping double quotes with `"\""` here?)

I'm surprised that: $ if [ -n "$(findmnt | grep "\""proc"\"" | head -n 1)" ]; then echo 1; else echo 2; fi 2 I've used "\"" before IIRC after ...
Martian2020's user avatar
  • 1,083
0 votes
2 answers
213 views

How do I convert this script into an alias (MacOS, ZSH) [duplicate]

This script works fine when directly typed into the console: N | find . -type f -iname "*.aac" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -acodec libmp3lame "${...
Vadorequest's user avatar
1 vote
2 answers
296 views

Please explain the behavior of these parameter expansions using IFS?

I'm trying to figure out how to use the ${parameter%word} expansion with $@ and $*. It started by trying to make a script to combine pdfs using ghostscript, but I ran into some weird behavior with ...
mangoduck's user avatar
0 votes
2 answers
647 views

How to properly parse a quoted arg-list string in a shell script?

Summary How to convert a single string a "b" 'c d' $'e\nf' into separate arguments, respecting quotes and preserving whitespaces and newlines? Question I'm trying to read and process the ...
jack's user avatar
  • 101
1 vote
2 answers
3k views

Bash: How do I quote shell arguments with spaces inside a variable containing multiple arguments without using an array? [duplicate]

In Bash, is it possible to pass a variable with a properly-quoted list of options to a command and not have it split on whitespace inside quotes? IOW, this script: MYCONFIG="--hi FOO=bar 'X=ABC ...
theory's user avatar
  • 127
0 votes
0 answers
25 views

Quoting inside [[ ]] in bash shell [duplicate]

Inside [[ ]] I do not need to quote variables right? Rather than if [[ "$flrm" == *"org"* || "$flrm" == "all" ]]; then printf '%s\n' "Delete: $fl" ...
Vera's user avatar
  • 1,183
1 vote
3 answers
2k views

How to use argument in single quotes

I have a file, which contains ids: 123abc 456dbc I want to pass them in to a command while I iterate over the the file. Currently, my command works like this: part_of_command '{"id":{"...
random's user avatar
  • 11
0 votes
2 answers
844 views

Sed can not replace when string contains double quotes

Output error from the execution of sed command: sed: -e expression #1, char 14: unterminated `s' command command file that I am trying to execute: #!/bin/sh old_version='\"version\": \&...
Ivelin Ivanov's user avatar
1 vote
2 answers
904 views

Array Declaration: Double Quotes & Parentheses

Perhaps this is a stupid question but two hours on Google hasn't turned up anything on point. Simply, does a difference exist in Bash between: X=" a b c " and X=( a b c ) The former ...
ebsf's user avatar
  • 281
0 votes
1 answer
1k views

Escaping "all prerequisites" variables in Makefile

Let's assume we have a couple of files whose names need to be quoted when used in a shell: echo A > 'a.$A' echo B > 'b.$B' And there is a Makefile with a rule that depends on these files: all: ...
Sergei Morozov's user avatar
0 votes
1 answer
120 views

Problem with command for memory stress - Unexpected end of string

I have a problem with this command in Python. stress-ng --vm-bytes $(awk '/MemAvailable/{printf "%d\n", $2 * 0.95;}' < /proc/meminfo)k --vm-keep -m 1 I need double quotation marks at the ...
Bronx's user avatar
  • 1
4 votes
2 answers
804 views

Bash's read builtin errors on a string-based timeout option specification but not an array-based one. Why?

In reading through the source to fff to learn more about Bash programming, I saw a timeout option passed to read as an array here: read "${read_flags[@]}" -srn 1 && key "$REPLY&...
qmacro's user avatar
  • 143
2 votes
2 answers
1k views

Removing single quotes from double-quoted variable element in array and run a command [duplicate]

I have a script where I dinamically change the arguments which must be passed to a command (mkvpropedit in this case). Consider the example script below: #!/bin/bash LANG_NAME="eng lish" ...
virtualdj's user avatar
  • 177
0 votes
1 answer
221 views

case-substring function and quoting

i use a simple function in a script in order to ckeck if a string contains a particular substring: #!/bin/bash # subs() { case $2 in *$1*) return 0 ;; *) ...
noemata's user avatar
3 votes
2 answers
209 views

Why does the command echo `echo \\\\\\\z` in bash script print \\z instead of \\\z?

The command echo `echo \\\\\\\z` is from this book , I don’t understand why it prints \\z when it get executed via the bash script. I think it should print \\\z
ll cool's user avatar
  • 31
2 votes
1 answer
92 views

Does + need to be escaped in find commands?

I have the following code in bash and I wonder on whether I can get rid of \+ and simply use + find "$fdir" \ -type f -name "*.org" -o -name ...
Pietru's user avatar
  • 371
2 votes
1 answer
697 views

issues with $ symbol while reading from positional parameters in unix shellscript

I have written the following script: #!/bin/bash TEST=$1 TEST_1=$2 if [[ "$TEST" == e ]];then echo $TEST_1 else echo "Input is not e" fi Now if I will run: sh test.sh e NS3#$xX$...
John's user avatar
  • 75
2 votes
2 answers
925 views

Unzip a .zip which includes directories with spaces in Name

I have a problem with unzipping my transfered .zip file. Firstly, I zipped a owncloud data directory with the encryption parameter. Then I transfered it to my new Server und would like to unzip it ...
Jan's user avatar
  • 23
1 vote
2 answers
719 views

How to quote exclamation marks in file names in a tcsh shell script with find and awk?

I have a script that searches for space characters ' ', exclamation marks '!' and dollar signs '$' in filenames and replaces each with an underscore '_'. However, it does not handle file names with ...
Ned64's user avatar
  • 8,546
3 votes
1 answer
4k views

Grep pattern that has double quotes and variable substitution surrounded by single quotes

So, Let's say I have the following pattern: Thisisatest="1" in a file called file. And I want to match the exact string above but for whatever reason, I choose to loop over some numbers ...
Nordine Lotfi's user avatar

1
2 3 4 5
22