Skip to main content

Questions tagged [quoting]

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

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
72