All Questions
107 questions
5
votes
2
answers
611
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 ...
0
votes
1
answer
147
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 ...
3
votes
1
answer
416
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 ...
1
vote
2
answers
395
views
Please explain the behavior of these parameter expansions using IFS?
I'm trying to figure out how to use the ${parameter%word} expansion with $@ and $*. It started by trying to make a script to combine pdfs using ghostscript, but I ran into some weird behavior with ...
4
votes
2
answers
1k
views
Bash's read builtin errors on a string-based timeout option specification but not an array-based one. Why?
In reading through the source to fff to learn more about Bash programming, I saw a timeout option passed to read as an array here:
read "${read_flags[@]}" -srn 1 && key "$REPLY&...
2
votes
2
answers
2k
views
Removing single quotes from double-quoted variable element in array and run a command [duplicate]
I have a script where I dinamically change the arguments which must be passed to a command (mkvpropedit in this case). Consider the example script below:
#!/bin/bash
LANG_NAME="eng lish"
...
7
votes
3
answers
711
views
How would you gracefully handle this snippet to allow for spaces in directories?
I have a series of commands, e.g.:
ssh -i key 10.10.10.10 mkdir -p "${DEST_PATH}/subdir1" "${DEST_PATH}/subdir2"
rsync "${SOURCE_PATH}" "$DEST_HOST:${DEST_PATH}/...
3
votes
1
answer
10k
views
Escaping backlash and double quotes inside a sed expression (surrounded by double quotes)
$ echo 'output: " ' | sed "s/\"/\"/"
output: "
$ echo 'output: " ' | sed "s/\"/\\\"/"
output: "
$ echo 'output: " ' | sed "s/\&...
-1
votes
1
answer
927
views
bash while loop irritate with single quote
I have a few lines code.
I just want to check if argument $1 is in the file with a while loop so I write this code.
#!/bin/bash
if [ ! -z $1 ]
then
update=$1;
while read line
do
if ...
3
votes
2
answers
1k
views
Globbing within a parameter expansion
I'm trying to select the files within a set of directories passed as arguments with the following:
${@/%/*}
However, this is not ideal, since paths with spaces will break, and quoting the parameter ...
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 ...
6
votes
3
answers
11k
views
How to prevent parameter expansion around a variable I want to be resolved?
Edit:
Important note before reading further: since Kusalananda's anwser, my question is now quite useless, since he pointed out a bug in another script I used. Now this bug is fixed, the below errors ...
73
votes
1
answer
14k
views
What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?
Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used?
Do ...
0
votes
3
answers
2k
views
Which quoting style GNU Bash variable definitions (mostly for paths)? [closed]
Which of the following quoting styles, for GNU Bash variables, is preferred and why?
Two double quotes: VAR="/path/$V1/path with space/$V2".
Multiple double quotes: VAR=/path/"$V1"/"path with space"/"$...
2
votes
2
answers
636
views
Using rsync to delete selected patterns, matches all files
I mean to use rsync to remove certain files (for Efficiently delete large directory containing thousands of files), in this case given to a shell script as patterns in the command line.
So far, this ...