Skip to main content

Questions tagged [quoting]

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

0 votes
1 answer
46 views

passing parameters to driver

I'm doing a Linux driver tutorial, and I have encountered a problem with the sample lesson of passing parameters to the driver.  I tried another parameter-passing example I found on the internet with ...
carlh's user avatar
  • 21
0 votes
2 answers
37 views

How to escape both single quotes and exclamation marks in bash

I have a long command and I just want to use alias to shorten it. But the command contains single quotes and exclamation marks. The origin command is ldapsearch -x -H ... -w 'abc!123'. I tried alias ...
Donghua Liu's user avatar
3 votes
1 answer
238 views

tcsh: Handle spaces in arguments when passing on to another command

I wrote a script that needs to call a command and pass on arguments. My script has its own parameters but some need to be passed through. This fails when arguments to my script have spaces in them. ...
Ned64's user avatar
  • 8,904
0 votes
0 answers
71 views

Why are my strings being truncated including and after an equals sign?

I was writing a shell script for inserting a string value through a Microsoft sqlcmd variable into a Microsoft SQL server database table and noticed some unexpected behavior. It appeared the trailing ...
Mark's user avatar
  • 101
0 votes
1 answer
65 views

How to use grep string that has double quotes in it

So I'm running a simple alias called vpn which runs a command and has an output, which I put into a .txt file. If interested to what exactly then here is the alias alias vpn="docker exec -it ...
Arelius's user avatar
  • 73
0 votes
1 answer
57 views

value of $VAR already contains backtick and/or single quote inside. How to handle it? How to properly pass $VAR to program? [duplicate]

$ bash --version GNU bash, versione 5.2.26(1)-release (x86_64-pc-linux-gnu) I don't know how to deal with $VAR when its value inside contains single quote (') and/or backtick (`). I'm in the need of ...
dAllARA's user avatar
  • 33
-1 votes
1 answer
42 views

I can't grep some inputrc string

bind -p |grep -E "\\e.\":" work but bind -p |grep -E "\\e\\C-.\":" don't work I tried a lot of combination
user3634569's user avatar
5 votes
1 answer
450 views

ls output display a file named "N'*" as "N'\''*"

System: Ubuntu 22.04.3 LTS GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) ls (GNU coreutils) 8.32 Situation: $ touch "N'*" $ ls 'N'\''*' "GNU Coreutils - Quoting File ...
yossi-matkal's user avatar
1 vote
1 answer
120 views

bash cd issue with path containing spaces: "too many arguments" [closed]

I created a path with spaces, and when I try to change directory I get "too many arguments" error message despite escaping the spaces or quoting the path : Here are the tests I made : # ...
creatldd1 creatldd1's user avatar
0 votes
1 answer
43 views

Replace string ${FOO} by ${'$'}{BAR} with sed

I have this string occurring N times in a file: ${FOO} that I have to replace by this string: ${'$'}{BAR} This is my current state: sed "s/\\${FOO}/\\${'\\$'}{BAR}/" file.txt but it raises &...
s.k's user avatar
  • 471
-1 votes
3 answers
94 views

How to use a variable in a command inside of a bash file

I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want: grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ...
TimLer's user avatar
  • 101
0 votes
0 answers
59 views

Why isn't passed quoted $@ a single argument? [duplicate]

Why isn't passed quoted $@ a single argument? f2() { echo "f2: $1" } f1() { local x=("$@") f2 "${x[@]}" } f1 x y Invocation: $ bash t537.sh f2: ...
pmor's user avatar
  • 619
0 votes
0 answers
45 views

escape in double and single quotation [duplicate]

I am confusing why bash can escape "..." but can't escape '...'? Can some one give me a hint? Thanks test@test:~$ echo "He said, \"Hello world\"" He said, "Hello ...
joe's user avatar
  • 53
0 votes
1 answer
77 views

How can I create a file named "\?$*'ChouMi'*$?\"?

I need to create a file with this exact name "\?$*'ChouMi'*$?\" so that ls would show it as: $ ls | cat -e "\?$*'ChouMi'*$?\"$ $
prince royce's user avatar
1 vote
1 answer
99 views

Why does -n with unquoted variable containing empty string return true? [duplicate]

From man bash: -n string True if the length of string is non‐zero. Examples: # expected $ var=""; [ -n "$var" ]; echo $? 1 # unexpected? $ var=""; [ -n $var ]; echo ...
pmor's user avatar
  • 619
2 votes
1 answer
224 views

How to proberly deal with quotes in filenames when using variables/arrays including the filenames in bash? [duplicate]

I have been working on a bash script for a few days and got stuck with filenames including single and double quotes. Give I want to iterate over the following files in a directory: 'file1.txt' 'file2....
benjamin10's user avatar
0 votes
0 answers
28 views

In the nullmailer `remotes` configuration file, how do I quote single quotes in the password?

I'd like to use nullmailer to have my Debian (bullseye and bookworm) systems send system-generated email messages to the appropriate recipient. nullmailer is configured (among others) by the file /etc/...
Binarus's user avatar
  • 3,410
0 votes
1 answer
82 views

Linux program to quote filename only when necessary?

Consider having these directories and files: $ tree /tmp/test /tmp/test ├── dir │   ├── file_normal │   ├── file with "double quote │   ├── file with 'single quote │   ├── file with space │   └── ...
midnite's user avatar
  • 443
0 votes
1 answer
47 views

What is the difference between quotes wrap around only the option value vs quotes wrap around the option name and option value?

What is the difference between quotes wrap around only the option value eg: grep --file="grep pattern file.txt" * vs quotes wrap around the option name and option value eg: grep "--...
Nor.Z's user avatar
  • 133
0 votes
1 answer
60 views

How can I edit matching files if the paths contain whitespace in bash?

I sometimes grep (or rg aka ripgrep or ag aka silversearcher) for things and then want to edit the matching files. For the editor part I use bash's history. ~$ rg someThing ./path/to/some/file.txt 1:...
Robert's user avatar
  • 156
0 votes
1 answer
129 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
  • 243
1 vote
1 answer
178 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
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 ...
Criggie's user avatar
  • 1,791
0 votes
1 answer
231 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
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 ...
Bog's user avatar
  • 1,034
0 votes
1 answer
68 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
2 answers
190 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
494 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
377 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
205 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
635 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,493
3 votes
1 answer
385 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
1 vote
1 answer
68 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
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 ...
togo's user avatar
  • 13
4 votes
2 answers
647 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
  • 3,132
3 votes
1 answer
402 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
474 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
  • 2,199
6 votes
1 answer
3k 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
132 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,270
7 votes
3 answers
3k 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
  • 875
0 votes
1 answer
41 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
  • 333
8 votes
1 answer
5k 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
  • 37.5k
2 votes
1 answer
942 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,730
1 vote
2 answers
7k 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
  • 83
3 votes
1 answer
278 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 U.U. Unixuser's user avatar
2 votes
2 answers
133 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
  • 15.6k
2 votes
1 answer
2k 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
892 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,724
2 votes
1 answer
58 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
57 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,219

15 30 50 per page
1
2 3 4 5
22