All Questions
453 questions
0
votes
2
answers
79
views
How does `*\ *` work in bash?
There is an answer from SuperUser, which renames filenames containing whitespace:
for f in *\ *; do mv "$f" "${f// /_}"; done
The part I don't understand is *\ *.
The author wrote ...
9
votes
1
answer
650
views
Why does bash give the following result after brace expansion?
I am using linux and the following version of the bash:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
When I type:
echo file{[1,2],3}.txt
I expect brace expansion to be done first, so:
...
0
votes
2
answers
131
views
variable assignment doesn't create one same object at least for grep
The problem is as follows (Here I don't use find since it doesn't support double-asterisk wildcard **):
$ FILES=(foo/**/*.suffix bar/**/*.suffix2)
$ grep baz "${FILES[@]}" # works
# I use ...
4
votes
1
answer
128
views
Bash extglob with ignored pattern
Suppose I have these files:
foo/bar/baz/test.js
foo/bar/baz/test.min.js
If I run:
shopt -s globstar
shopt -s extglob
echo foo/bar/**/*!(.min).js
...that will nonetheless match the test.min.js file.
...
-2
votes
4
answers
70
views
gnu grep multiple filters in one regex [closed]
RHEL 8, if it matters.
I need to find all the rows in a text file which match these three filters:
cut -f1 -d: .pgpass | grep ^FISP | grep -E 'CDS|TAP' | grep PGS401
FISPCDSPGS401A
FISPCDSPGS401B
...
4
votes
4
answers
313
views
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH.
I somehow accidentally ran a shell script with commented out ...
-1
votes
2
answers
165
views
How to concatenate strings containing asterisks in bash
I have 2 variables:
file1=file1_*.txt
file2=file2_*.txt
The actual names of the files are: file1_FY24Q3.txt and file2_FY24Q3.txt and they change every quarter. I want to concatenate these vars into ...
-2
votes
1
answer
128
views
Behavior of truncating multiple slashes in paths stemming from glob pattern matching
From my limited research it seems that in bash, any multiple slashes after a glob pattern are truncated, like so:
echo ////[h]ome////user////Desktop////test////
# outputs ////home/user/Desktop/test/
...
2
votes
1
answer
56
views
Untangling pathname expansion and quote removal in echo 'a'*
Shell is: GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
In the current working directory, there are two files:
a file named abc.txt
a file named 'a'bc.txt (created with touch \'a\'bc.txt)
...
0
votes
0
answers
24
views
Exclude a filename suffix from glob match [duplicate]
I've read the documentation but couldn't find the answer to what I wanted to achieve. I have the following files:
$ ls
a a. a.b ab a.c ac
I have the extglob shell option enabled. I want to ...
4
votes
1
answer
592
views
Why does filtering a bash array using negative pattern matching and parameter expansion have unexpected results?
I'm doing a small-ish pure bash script to roll dice; as such I'm having to manipulate arrays. I want to do something akin to a filter operation in other languages: extract some of the things in the ...
1
vote
1
answer
182
views
Expand a list of files including globs, which are defined in a file
I'm using bash. Suppose I have a file named filelist, which contains a list of files:
stuff/**/*.csv # to keep it simple (without loops), assume just one entry
#*.txt
#foo.md
#bar.bin
And I want ...
2
votes
2
answers
216
views
Matching negative patterns with bash extglob
Consider I have a set of seven files:
item1_data
item2_data_more
item3_data
item4_data
item5_data_more
other6_data
other7_data_more
and I want to match the three of them that begin with item but do ...
2
votes
0
answers
76
views
Pattern list in bash extglob containing a / and a |
Here is a transcript of commands (and their output) that explains my problem:
/tmp/example $ shopt -s
cdspell on
checkwinsize on
cmdhist on
complete_fullquote on
direxpand ...
0
votes
1
answer
138
views
How to reuse matched value in bash globbing? [duplicate]
I was wondering whether it is possible to reuse whatever was matched in a path with globbing? (Just as it can usually be done with regex substitutions?)
I'm aware that there are other solutions for ...