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....

15 30 50 per page
1
2 3 4 5
36