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
8 votes
1 answer
1k 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.
user avatar
  • 33.3k
2 votes
1 answer
166 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 ...
user avatar
  • 5,234
0 votes
2 answers
352 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 ...
user avatar
  • 51
3 votes
1 answer
75 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 ...
user avatar
2 votes
2 answers
36 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) ]...
user avatar
  • 13k
1 vote
1 answer
229 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, ...
user avatar
2 votes
2 answers
60 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. ...
user avatar
  • 3,362
2 votes
1 answer
28 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 "\...
user avatar
0 votes
1 answer
27 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 ...
user avatar
0 votes
2 answers
37 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 "${...
user avatar
1 vote
2 answers
248 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 ...
user avatar
-1 votes
2 answers
129 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 ...
user avatar
  • 99
0 votes
3 answers
428 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 ...
user avatar
  • 117
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" ...
user avatar
  • 53
1 vote
3 answers
46 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":{"...
user avatar
  • 11
0 votes
2 answers
395 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\": \&...
user avatar
1 vote
2 answers
177 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 ...
user avatar
  • 155
0 votes
1 answer
265 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: ...
user avatar
0 votes
1 answer
65 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 ...
user avatar
  • 1
4 votes
2 answers
425 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&...
user avatar
  • 143
2 votes
2 answers
410 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" ...
user avatar
  • 177
0 votes
1 answer
42 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 ;; *) ...
user avatar
3 votes
2 answers
143 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
user avatar
  • 31
2 votes
1 answer
69 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 ...
user avatar
  • 319
2 votes
1 answer
383 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$...
user avatar
  • 61
2 votes
2 answers
369 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 ...
user avatar
  • 23
1 vote
2 answers
293 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 ...
user avatar
  • 7,647
3 votes
1 answer
576 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 ...
user avatar
5 votes
3 answers
584 views

How to recursively set directory permissions with a find that lacks -exec?

My Qnap NAS is cursed with a find command that lacks the -exec parameter, so I have to pipe to something. The shell is: GNU bash, version 3.2.57(2)-release-(arm-unknown-linux-gnueabihf) I'm trying to ...
user avatar
1 vote
1 answer
201 views

How to insert ESC control characters in a file in FreeBSD?

I want to enclose Fortran comments with two escape commands (ESC+E and ESC+F). This implies detecting the comment that begins with ! until end of line, and prefixing it with ESC+E and suffixing it ...
user avatar
  • 569
5 votes
3 answers
976 views

How to match a literal string containing an unclosed quote with ripgrep?

I have a file that contains the some python code. There is a line that contains the following(including the quotes) 'hello "value"' I want to search 'hello "value" in the file. ...
user avatar
0 votes
1 answer
115 views

BASH ANSI-C Quoting - what is the Escape character \E

According to the GNU Bash manual (section 3.1.2.4 ANSI-C Quoting) $'\E' should expand to "an escape character (not ANSI C)". What is this escape character? Is it the character equivalent to ...
user avatar
  • 1,441
0 votes
2 answers
38 views

Pass qouted filename with spaces in a bash variable [duplicate]

In a bash shell, consider this: $ x="-name 'foo bar'" $ find $x find: paths must precede expression: `bar'' $ find -name 'foo bar' ./foo bar What can I put in $x to make find $x behave like ...
user avatar
  • 1
0 votes
0 answers
17 views

ASH scripting quotes in backticks works with echo but not with actual execution [duplicate]

I am creating a script for my router (running busybox). In my script I generate a command in a variable like nvram set option='value with spaces' but when it is executed it complains that arguments ...
user avatar
  • 101
1 vote
1 answer
777 views

Using single quotes inside input of heredocs

I need some help debugging my tcsh script. It uses heredocs. The code: <pre_setup> <<EOF1 <setup> <<EOF2 <command> exit 0 EOF2 exit 0 EOF1 The <pre_setup> is ...
user avatar
  • 83
0 votes
1 answer
172 views

What exactly these tr commnads do?

I am rewriting some commands that were run using WSL on a Windows machine and need to accomplish the same thing in Python. I am having a really hard time figuring out what exactly these commands are ...
user avatar
2 votes
1 answer
636 views

How to escape all of the special characters in order to be able to print the string as is?

I'm creating a tcsh script on the fly (with a static language). I have a <add-command-here> section that contains some command. I want to do: echo <add-command-here> In that <add-...
user avatar
  • 83
1 vote
0 answers
99 views

How to move all the files with specific prefix of the directory? [duplicate]

I have a following directory structure (assume no two files have the same name): Apple1 apple1.jpg apple2.jpg Apple2 apple3.jpg apple4.jpg Apple3 Tomato Peach And i would like to move one ...
user avatar
3 votes
4 answers
459 views

Using cut with pling/exclamation mark as a delimiter

In shell (not Bash) I have a string like this that I want to parse: stringhere/morestring!99 After parsing, I want to keep the 99 at the end, and throw away the rest of the string. The substring that ...
user avatar
  • 141
3 votes
1 answer
88 views

Why does substituting eval with declare (for creating dynamic variables) result in an empty variable?

With bash >5, I'm trying to assign a different value to variables depending on the architecture specified in a variable. I use a function to do so. This works perfectly: # arguments: variable ...
user avatar
3 votes
1 answer
100 views

Cannot understand this bash shell argument expansion

Totally crazy about the following commands: declare -a partition_files readarray -d '' partition_files < <(find "$choosen_image_folder" -name "*sda${i}.gz*") # this does not ...
user avatar
  • 141
0 votes
0 answers
28 views

How to iterate over matches which contain spaces [duplicate]

I have a file that looks like this # ... stuff @late() def test1(): # ... @late() def test2(): # ... I need to get each match after the @late() line and do some work on them. I've tried ...
user avatar
5 votes
2 answers
421 views

Why does quoting not protect filenames that start with "-" against mis-interpretation? [duplicate]

This might be a ridiculous post, but let's say we have a file called -|h4k3r|-, why doesn't this quoting work? cat '-|h4k3r|-' I thought single quotes remove meaning of all special characters? ...
user avatar
  • 153
0 votes
2 answers
86 views

Converting multiline to single line in a file looses double quotes

Here is my sample file cat test.txt "IND WEB", "Speed Web (Internal webserver)", "Web Bill", I tried the below two solutions to convert multiline to single line however ...
user avatar
  • 307
0 votes
2 answers
167 views

Bash interpreting special character within single quotes [duplicate]

Ran into some unexpected but interesting behavior. I was doing a somewhat complex execution when I ran into a situation that from my understanding of how Bash handles characters shouldn't have ...
user avatar
  • 339
0 votes
1 answer
41 views

Putting single quote in the begining of column

I have a .txt file with publications for which columns are separated by a single space. However, titles also have spaces an in order to separate the columns correctly I need to have all titles in ...
user avatar
  • 1
1 vote
1 answer
1k views

grep: use square brackets to match specific characters

So I am experimenting with the power of grep using this resources The problem I am currently encountering is that it doesn't seem to work as I intended. so I have an demo.txt file that contains foo....
user avatar
  • 171
7 votes
3 answers
582 views

How would you gracefully handle this snippet to allow for spaces in directories?

I have a series of commands, e.g.: ssh -i key 10.10.10.10 mkdir -p "${DEST_PATH}/subdir1" "${DEST_PATH}/subdir2" rsync "${SOURCE_PATH}" "$DEST_HOST:${DEST_PATH}/...
user avatar
  • 118
0 votes
1 answer
51 views

How to set sed command correctly

When I try following commands, (I'd like to rewrite sql). Day='2020/12/1' Dir=/home/test/data sql=`cat $Dir"/"$test".sql" | sed -e "s/Day/$Day/g"` I suffered following ...
user avatar
3 votes
1 answer
1k views

Escaping backlash and double quotes inside a sed expression (surrounded by double quotes)

$ echo 'output: " ' | sed "s/\"/\"/" output: " $ echo 'output: " ' | sed "s/\"/\\\"/" output: " $ echo 'output: " ' | sed "s/\&...
user avatar
  • 33

1
2 3 4 5
21