All Questions
13
questions
4
votes
2
answers
653
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 ...
0
votes
2
answers
884
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 ...
1
vote
1
answer
973
views
Command substitution inside double quotes
I am attempting to write a bash parser. Many resources have referred to this wiki
One area I am getting stuck is why the following would work
echo "$(echo "hi")" # output => ...
0
votes
2
answers
75
views
Why are aliases skipped if escaped?
A common way to skip aliases is to add a backslash before the aliased command.
For example,
$ alias ls='ls -l'
$ ls file
-rw-r--r-- 1 user user 70 Jul 30 14:37 file
$ \ls file
file
My research has ...
2
votes
2
answers
368
views
What is the right way to quote nested parameter expansions?
When dealing with with nested parameter expansions, which of these is the correct way to quote things?
This one:
var="${var#"${var%%[![:space:]]*}"}"
Or this one:
var="${var#${var%%[![:space:]]*}}"...
0
votes
2
answers
834
views
Is the behavior of escaping special characters inside double-quotes in mainstream POSIX-compliant shells at odds with POSIX?
Per the POSIX Shell Command Language Page:
\
The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
3
votes
3
answers
4k
views
POSIX Shell: inside of double-quotes, are there cases where `\` fails to escape `$`, ```, `"`, `\` or `<newline>`?
Per the POSIX Shell Command Language Page:
\
The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
6
votes
3
answers
7k
views
shell: Quote string with single quotes rather than backslashes
How can I quote a string with single quotes?
Eg, I can do:
$ printf "%q\n" 'two words'
two\ words
$
Is there a way to get a single- (or double-) quoted string as output, ie:
$ MAGIC 'two words'
'...
5
votes
1
answer
10k
views
Escape double quotes in variable
I would like to put this command into a file to be run later:
ln -s "$xr"/ya.txt ~
I can do that with (1):
cat > zu.sh <<eof
ln -s "$xr"/ya.txt ~
eof
or (2):
printf 'ln -s "%s"/ya.txt ~\...
9
votes
1
answer
902
views
What does `\time`, `t\ime` and `\cd` actually do? (fun with backslashes in shells)
While discussing over the differences between /usr/bin/time and the shell (bash and zsh) built-in time, someone mentioned that one can use \time as a shorthand to get /usr/bin/time.
First it seemed ...
5
votes
1
answer
3k
views
Any problem assigning one variable to another in shell without using quotes? [duplicate]
This question is about assigning the entire contents of one variable to another variable.
Variable is not being used (sent to echo, etc.)
No parameter expansion is being done during the assignment.
...
17
votes
2
answers
7k
views
POSIX compliant way to work with a list of filenames possibly with whitespace
I have seen Bash scripting guides suggesting the use of array for working with filenames containing whitespace. DashAsBinSh however suggests that arrays are not portable so I am looking for a POSIX ...
217
votes
3
answers
105k
views
$VAR vs ${VAR} and to quote or not to quote
I can write
VAR=$VAR1
VAR=${VAR1}
VAR="$VAR1"
VAR="${VAR1}"
the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?