All Questions
64
questions
0
votes
1
answer
41
views
How Can I Interpret Quoted Wildcards
I am writing a shell script and I need to interpret quoted wildcards.
"R Programming*"
I do not want the * asterisk to be taken literally.
I want it to be interpreted as a wildcard.
"R ...
2
votes
2
answers
133
views
Test fails (correctly) on command line, but succeeds (incorrectly) in script
For the sake of this question, assume that the glob /a/b/c/* produces no matches.
This means that the following test should fail (in other words, it should produce a non-zero $?):
[[ -n /a/b/c/*(#qN) ]...
1
vote
1
answer
2k
views
grep: use square brackets to match specific characters
So I am experimenting with the power of grep using this resources
The problem I am currently encountering is that it doesn't seem to work as I intended. so I have an demo.txt file that contains foo....
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
1
answer
1k
views
Unable to run npm install with version specification
I am trying to run a simple npm install with zsh terminal.
npm install --save-dev @typescript-eslint/eslint-plugin@^4.0.0
zsh: no matches found: @typescript-eslint/eslint-plugin@^4.0.0
It appears ...
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 ...
1
vote
1
answer
287
views
UNIX KSH - Using double quotes or no quotes when assigning strings with wildcard to a variable?
I am new to UNIX and currently working on a shell script where I will be receiving files with names such as abc_123_date.zip so the file names will be abc_123_12312005. Instead of hardcoding abc_123_*....
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 ...
10
votes
1
answer
17k
views
Using a variable as a case condition in zsh
My question is the zsh equivalent of the question asked here: How can I use a variable as a case condition? I would like to use a variable for the condition of a case statement in zsh. For example:
...
10
votes
2
answers
9k
views
ls with a wildcard
This works from the terminal:
ls /dev/sda*
I want it in a bash script, using a variable. I tried:
device="a"
ls "/dev/sd"$device"*"
But I get the error: ls: cannot access '/dev/sda*': No such file ...
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 ...
1
vote
1
answer
325
views
grep not working when I enclose the directory in double quotes
When I do something like this:
grep "hello" /home/paul/*
It works.
But when I do something like this:
grep "hello" "/home/paul/*"
grep display the error:
grep: /home/paul/*: No such file or ...
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 ...
0
votes
2
answers
672
views
What is the difference between '*.txt' and *.txt?
I was completing the git tutorial found here:
https://try.github.io/levels/1/challenges/7
And it said that I had to put single quotes around *.txt. I had not seen this before when using linux but ...
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
1
answer
276
views
ls -l seems to give one concatenation of the filenames found in a directory
I want to write a shellscript to convert all .ogg files in a directory to .mp3 files.
The filenames contain spaces, so I use a lot of double quotes in the sequenco of commands. The command I use is
...
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 ...
0
votes
2
answers
83
views
In what way does quoting parameters to `find` matter? [duplicate]
When looking for txt files, I run this command:
find . -name "*.txt" -print
This gives me a list of all the text files beneath current directory.
However, find . -name *.txt -print gives me the ...
5
votes
1
answer
235
views
Why file glob expansion is not suppressed
I have the following script my.sh:
echo $@
Now I want to see file glob expansion, so I do like this and it works OK:
$ bash my.sh *
$ f1 f2 my.sh
Now, I've tried suppress expansion using ...
7
votes
2
answers
6k
views
OpenSSH: Prevent globbing on SSH_ORIGINAL_COMMAND
I have the following setup where I use an OpenSSH server to remotely start a certain command using ssh.
My authorized_keys file has the following entry:
command="/path/to/script.sh $...
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 $...
0
votes
2
answers
3k
views
Wildcard not working in quotes
The script is supposed to loop over subdirectories and match all the filenames (FLA.*Image.*file.jpg and FLA.*Image.jpg) in subdirectories and process it. It also create output folder inside the ...
5
votes
1
answer
8k
views
Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]
On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
2
votes
1
answer
4k
views
Cannot stop bash to expand star (wildcard character) passed to app from shellscript
I have a shell bash script wich should pass the star ["*"] wildcard character to an application without using quotation marks.
I am reading since hours and always find to use "set -f" inside the ...
0
votes
1
answer
1k
views
globbing and wildcards
Are wildcards ever supposed to be expanded for a program that is not the first in the pipeline? Every example uses wildcard for the first program in the pipelilne.
For example, the following does ...
9
votes
1
answer
1k
views
Why does `grep fil*` fail?
I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds.
I don't understand it, can someone explain?
4
votes
2
answers
159
views
confusing about double quoting
I learned when I use command, double quoting treat all things as character except $, `, \ .
But, when use command like find -type f -name "*.jpg" *.jpg is inside double quotes. Then, it means we want ...
2
votes
1
answer
2k
views
Globbing error due to whitespace
My directory variable
POSTMAP="/work/Documents/Projects/untitled\ folder/untitled\ folder/*/*_tsta.bam"
My for statement:
for file0 in ${POSTMAP}; do
...
It seems that the whitespace in 'untitled ...
4
votes
4
answers
3k
views
How to escape shell metacharacters automatically with `find` command?
I've got a bunch of XML files under a directory tree which I would like to move to corresponding folders with the same name within that same directory tree.
Here is sample structure (in shell):
...
6
votes
2
answers
8k
views
How to store a path built with wildcards and containing with spaces into a variable
Here's the situation (I'm on a Mac, OS X El Capitan):
# This works:
$ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/;
# These do not work:
$ INSTALL_DIR=/Applications/...
1
vote
1
answer
119
views
find command match issue [duplicate]
I'm having some trouble while searching files with find command and the way it handles the search.
Let's say I'm currently in the directory /tmp and the directory contains the files: backup-20151219....
2
votes
1
answer
1k
views
bash regex: asterisk gives ambiguous search results with grep
I am using a simple text file to test the * meta-character through grep.
The text file is as below:
1
11
111
1111
11111
111111
d
da
daa
daaa
b
bc
bcc
bccc
Now when I search digit 1 using grep like ...
1
vote
2
answers
1k
views
Internal expansion with the find command and wildcard character [duplicate]
I'm still learning the command line and I am having some trouble fully understanding the use of the wildcard within the find command.
I'm working in the directory user/temp and use the find command ...
1
vote
1
answer
514
views
Having trouble with img2pdf and spaces in filenames
I am trying to convert a bunch of jpeg files to a pdf file.
When I type the filenames with the quotes all is fine:
$ img2pdf "./Page 001.jpg" "./Page 002.jpg" -o book.pdf
When I go for the ...
3
votes
3
answers
3k
views
Why are square brackets preventing shell expansion?
'4800483343' is a directory, and 'file1' & 'file2' are two files in it.
Why is the following happening?
$ ls 4800483343
file1 file2
$ md5sum 4800483343/*
36468e77d55ee160477dc9772a99be4b ...
3
votes
4
answers
4k
views
Bash: move files of specific pattern
I write a script that iterates over a set of zip files, extracts them and moves only files that match a specific filename pattern to another folder.
The script:
#!/bin/bash
ARCHIVE_FILEMASK="????-??...
2
votes
2
answers
1k
views
Cannot run command inside bash variable including square brackets with nullglob
Assuming I want to run commnand stored inside the variable with nullglob turned on. For example:
shopt -s nullglob
a="echo [foo]bar"
${a}
This gives me an empty output due to the nullglob option of ...
-1
votes
1
answer
636
views
Assign regular expression as character for a variable
I am wondering is there is a way to assign a regular expression as a character in a string to a variable and not have the regular expression change my variable.
For example:
in my directory I am ...
2
votes
1
answer
3k
views
Copy array of multiple files with globbed extensions, in bash 3.2
I've found bits and pieces of each of the things I want to do across the Web, but nothing exactly fits my use case.
I'm trying to write a script that copies multiple specific files to a directory on ...
2
votes
3
answers
350
views
grep .* returns results from .bash_history and complains about
I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content:
Lady of ...
10
votes
1
answer
11k
views
Bash substitution with variable defined from a glob pattern
The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution?
#!/bin/bash
FILEPATH_WITH_GLOB="/home/user/file_*"
...
2
votes
2
answers
7k
views
tar exclude files *.zip
Why don't *.zip patterns work in tar :
tar cfjv backup.tar.bz2 --exclude mydir/files/*.zip mydir
Is there another syntax?
5
votes
2
answers
6k
views
scp command behaves differently when used with expect utility
expect -c 'spawn scp -C -o CompressionLevel=9 ~/partFiles/* [email protected]:/export/home/abc/; sleep 10; expect password; send "secretPassword\n";interact'
throws - ~/partFiles/*: No such file or ...