All Questions
503
questions
4
votes
2
answers
948
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
1k
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"
...
0
votes
1
answer
382
views
case-substring function and quoting
i use a simple function in a script in order to ckeck if a string contains a particular substring:
#!/bin/bash
#
subs() {
case $2 in
*$1*)
return 0 ;;
*)
...
3
votes
2
answers
280
views
Why does the command echo `echo \\\\\\\z` in bash script print \\z instead of \\\z?
The command
echo `echo \\\\\\\z`
is from this book , I don’t understand why it prints
\\z
when it get executed via the bash script.
I think it should print
\\\z
2
votes
1
answer
99
views
Does + need to be escaped in find commands?
I have the following code in bash and I wonder on whether I can get rid of \+ and simply use +
find "$fdir" \
-type f -name "*.org" -o -name ...
5
votes
3
answers
1k
views
How to recursively set directory permissions with a find that lacks -exec?
My Qnap NAS is cursed with a find command that lacks the -exec parameter, so I have to pipe to something. The shell is: GNU bash, version 3.2.57(2)-release-(arm-unknown-linux-gnueabihf)
I'm trying to ...
0
votes
1
answer
729
views
BASH ANSI-C Quoting - what is the Escape character \E
According to the GNU Bash manual (section 3.1.2.4 ANSI-C Quoting) $'\E' should expand to "an escape character (not ANSI C)". What is this escape character? Is it the character equivalent to ...
0
votes
2
answers
476
views
Pass qouted filename with spaces in a bash variable [duplicate]
In a bash shell, consider this:
$ x="-name 'foo bar'"
$ find $x
find: paths must precede expression: `bar''
$ find -name 'foo bar'
./foo bar
What can I put in $x to make find $x behave like ...
3
votes
1
answer
338
views
Why does substituting eval with declare (for creating dynamic variables) result in an empty variable?
With bash >5, I'm trying to assign a different value to variables depending on the architecture specified in a variable. I use a function to do so. This works perfectly:
# arguments:
variable ...
3
votes
1
answer
110
views
Cannot understand this bash shell argument expansion
Totally crazy about the following commands:
declare -a partition_files
readarray -d '' partition_files < <(find "$choosen_image_folder" -name "*sda${i}.gz*")
# this does not ...
5
votes
2
answers
496
views
Why does quoting not protect filenames that start with "-" against mis-interpretation? [duplicate]
This might be a ridiculous post, but let's say we have a file called -|h4k3r|-, why doesn't this quoting work?
cat '-|h4k3r|-'
I thought single quotes remove meaning of all special characters?
...
2
votes
2
answers
696
views
Bash interpreting special character within single quotes [duplicate]
Ran into some unexpected but interesting behavior. I was doing a somewhat complex execution when I ran into a situation that from my understanding of how Bash handles characters shouldn't have ...
7
votes
3
answers
676
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
9k
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/\&...
2
votes
1
answer
1k
views
How to work around wildcard inside double quotes? [duplicate]
In bash, the file globbing * doesn't work inside double quotes, but my filename contains whitespace, so I need to double quote filename before passing it to a shell script. How can I do that?
For ...