Skip to main content

Questions tagged [quoting]

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

2 votes
1 answer
2k views

escaping filename results from grep

How do I escape the output of grep so that bash can read the file names correctly? I have a text file that is the output of a find command. For each line, I want to make a symlink. For now, I'm just ...
0 votes
1 answer
51 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 ...
18 votes
4 answers
5k views

Is there a command to write text to a file without redirection, pipe or function?

Pipes and redirection are two of the most powerful functions in Linux, and I love them. However, I'm stuck with a situation where I need to write a fixed piece of text to a file without using a pipe, ...
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 ...
4 votes
2 answers
1k views

Is there a way to printf $@ verbatim?

I want to write a script that echoes to stdout its $@ verbatim, including any potential double-quotes, without a newline. What I have tried: > cat ./script1 #! /usr/bin/bash printf "%s %s" $0 ...
3 votes
1 answer
249 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. ...
4 votes
3 answers
2k views

How to pass argument with char ( in remote path?

I'm trying to move a file with rsync to a remote location, The file has be be named : DRRS_(H264).mp4 but when I try : rsync -azR output.mp4 [email protected]:encoded/somepath/DRRS_(H264).mp4 it ...
0 votes
0 answers
76 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 ...
0 votes
1 answer
78 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 ...
2 votes
1 answer
479 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/...
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 ...
0 votes
2 answers
2k views

Exclude the output from ssh and only log the error if found

typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} " $(cat); IFERROR=$(checkscript); echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1 This line...I can't exclude the "...
-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
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 ...
34 votes
4 answers
168k views

What is the difference between echo `date`, echo "`date`", and echo '`date`'?

What is the difference between these three commands? echo `date` echo "`date`" echo '`date`' I am confused on what the differences actually are. I think that when the ' are around it means that it ...
1 vote
1 answer
130 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 : # ...
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 &...
1 vote
1 answer
202 views

Tab character in exiftool

I need to insert tab character on place of _ between day and hour. exiftool -T -r -filename -CreateDate -d "%Y%"."%m%"."%d_%H%"."%M%"."%S" /Users/***/***/testmapa/mapa2/ > /Users/***/***/testmapa/...
2 votes
2 answers
734 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
-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 ...
33 votes
5 answers
145k views

Why is echo ignoring my quote characters?

The echo command isn't including the complete text that I give it. For example, if I do: $ echo ' echo PARAM=` grep $ARG /var/tmp/setfile | awk '{print $2}' ` ' It outputs: echo PARAM=` ...
20 votes
6 answers
951 views

Should variables be quoted when executed?

The general rule in shell scripting is that variables should always be quoted unless there is a compelling reason not to. For more details than you probably want to know, have a look at this great Q&...
275 votes
4 answers
53k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
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: ...
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 ...
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'*$?\"$ $
19 votes
1 answer
46k views

What characters need to be escaped in files without quotes?

I have browser-based shell/terminal that executes bash commands and I'm escaping spaces but it turns out that parenthesis also need to be escaped. What other characters need to be escaped for file ...
32 votes
1 answer
9k views

How to ensure that string interpolated into `sed` substitution escapes all metachars

I have a script that reads a text stream and generates a file of sed commands that is later run with sed -f. The generated sed commands are like: s/cid:image002\.gif@01CC3D46\.926E77E0/https:\/\/...
1 vote
1 answer
100 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 ...
2 votes
1 answer
229 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....
0 votes
2 answers
984 views

CSV fields max length error and setting quoting=csv.QUOTE_NONE

After running csvcut on a comma-delimited .csv file: [root@server files]# csvcut -c title,mpn,overview,techspecs2,image_carousel_elargesrc syn_multi-image.csv > syn_scraped_cut.csv I get the error:...
197 votes
6 answers
300k views

How can we run a command stored in a variable?

$ ls -l /tmp/test/my\ dir/ total 0 I was wondering why the following ways to run the above command fail or succeed? $ abc='ls -l "/tmp/test/my dir"' $ $abc ls: cannot access '"/tmp/test/my': No ...
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/...
0 votes
1 answer
85 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 │   └── ...
0 votes
1 answer
48 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 "--...
23 votes
6 answers
28k views

How to assign space-containing values to variables in bash using eval

I want to dynamically assign values to variables using eval. The following dummy example works: var_name="fruit" var_value="orange" eval $(echo $var_name=$var_value) echo $fruit orange However, when ...
181 votes
1 answer
78k views

When is double-quoting necessary?

The old advice used to be to double-quote any expression involving a $VARIABLE, at least if one wanted it to be interpreted by the shell as one single item, otherwise, any spaces in the content of $...
18 votes
2 answers
106k views

How to use a special character as a normal one in Unix shells?

Many questions like 'How to type the double-quote char (")?' are being asked, and we don't want to clutter our community with the same answer (Type it as \" if not enclosed in 's, " if enclosed in 's.)...
1 vote
2 answers
672 views

Problem sending SMS text with a single quote character - mmcli (ModemManager)

This is an example from the mmcli manpage: mmcli -m 0 --messaging-create-sms="text='Hello world',number='+1234567890'" The details how it is parsed are unclear, the description says only --messaging-...
0 votes
1 answer
61 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:...
7 votes
4 answers
4k views

Multiline variable with spaces, adding each line to an array

I have a problem I can't seem to figure out.. I'm making a script I will run in OSX to help me stay connected to open wifi hotspots. I am reading all surrounding wifi networks into a muntiline ...
0 votes
1 answer
133 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 ...
1 vote
1 answer
181 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 ...
155 votes
5 answers
471k views

How to escape quotes in the bash shell?

I'm having trouble with escaping characters in bash. I'd like to escape single and double quotes while running a command under a different user. For the purposes of this question let's say I want to ...
20 votes
2 answers
12k views

How Can I Expand A Tilde ~ As Part Of A Variable?

When I open up a bash prompt and type: $ set -o xtrace $ x='~/someDirectory' + x='~/someDirectory' $ echo $x + echo '~/someDirectory' ~/someDirectory I was hoping that the 5th line above would have ...
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 ...

15 30 50 per page
1
2 3 4 5
22