All Questions
26
questions
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 ...
2
votes
3
answers
317
views
How to double quote a wildcard pattern of files?
I've seen a bunch of similar questions to this one but none exactly the same.
I have a directory of files which I want to pass in as a single, double-quoted argument to a command, using wildcard ...
3
votes
2
answers
954
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 ...
2
votes
1
answer
7k
views
Cannot rm or cp files with a wildcard in name [duplicate]
I have a line like this in my script:
rm "$TEMP_DIR/*.txt"
It fails with this output:
rm: cannot remove 'temp/*.txt': No such file or directory
I don't understand why doesn't that work. What am I ...
0
votes
0
answers
16
views
How to append a "/*" to the end of a variable with spaces and glob it? [duplicate]
If I have a directory wibble, the following command does what I want:
WIBBLE=wibble
wc $WIBBLE/*
If I have a directory foo bar, the following command does what I want:
wc foo\ bar/*
But this doesn'...
2
votes
1
answer
788
views
Loop that lists folders with spaces
Approach
I have a directory with named folders, randomly, with blank spaces and periods.
I created a small loop (in a script) with the intention of renaming these folders.
On the basis that these ...
16
votes
2
answers
5k
views
How are double quotation marks in bash matched (paired)?
I am using GNU bash 4.3.48. Consider the following two commands that only differ by a single dollar sign.
Command 1:
echo "(echo " * ")"
Command 2:
echo "$(echo " * ")"
The output of them are, ...
0
votes
3
answers
1k
views
Can’t echo variable value=* in script [duplicate]
Content of myfile:
123
**1
**
Script that attempts to display each word:
for i in $(cat $myfile)
do
echo "$i"
done
the result is when echo *, it lists the files in my current ...
2
votes
2
answers
10k
views
How to use the ls ? option in a bash variable?
I want to use the ls ? option in a Bash variable.
How do I get the script to do the same thing as ls -lt foobar_??????.log ?
$ cat foobar_ls.sh
#!/bin/bash
FOOBAR_LIST="foobar_??????.log"
ls -lt "$...
-2
votes
2
answers
625
views
why command not working properly when wildcard is detected
segment of code from shell script
fname=$(sed 's/(.*//' <<< $p | awk '{ print $NF }')
if [[ $fname == *['!'@#\$%^\&*()_+]* ]]
then
flag1=0
fi
where $p is one line from a text ...
-4
votes
1
answer
325
views
Folder exclusion formatting issue
I'm trying to create make targets for flawfinder and cppcheck that will recursively search the current directory, but ignore directories named "Test".
However, I have run into some issues with ...
1
vote
1
answer
111
views
Shell expansion not happening
Why are these two commands equivalent (or so it seems based on the results I get back)? I figured the first command wouldn't work because the * would be treated as the glob operator but instead it got ...
0
votes
2
answers
108
views
Loop space directory name [duplicate]
I have a CT.txt with below input data.
CT.txt:
test testing test 1
And with below script:
#!/bin/bash
for CITY in $(cat /home/user/CT.txt)
do
FILES=/mnt/dir1/dir2/$CITY/*
echo $FILES
Giving me ...
32
votes
5
answers
53k
views
How to make bash glob a string variable?
System Info
OS: OS X
bash: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
Background
I want time machine to exclude a set of directories and files from all my git/nodejs project. My ...
-1
votes
1
answer
331
views
bash is changing my tr statement
Running a bash (4.1.2) script with the trace options -v and -x the following code
for Option in "$@"; do
OptName=$(echo $Option | tr [:lower:] [:upper:])
results in
+ for Option in '"$@"'
echo $...