Skip to main content

All Questions

Tagged with
56 votes
1 answer
33k views

Wildcards inside quotes

This will be an easy one, but in my memories, when shell scripting, using double quotes would allow expanding globbing and variables. But in the following code: #!/bin/sh echo *.sh echo "*.sh" echo ...
ptpdlc's user avatar
  • 683
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 ...
John Siu's user avatar
  • 4,785
30 votes
5 answers
59k views

Bash script error with strings with paths that have spaces and wildcards

I am having trouble getting the basics of Bash scripting down. Here's what I have so far: #!/bin/bash FILES="/home/john/my directory/*.txt" for f in "${FILES}" do echo "${f}" done All I want to ...
learningtech's user avatar
25 votes
2 answers
19k views

Delete all files starting with a question mark

I have a folder in which I have around 4k files. Some of these files start with a a ? or ! character. I need to delete them but can't find an expression that would do so: rm -f ./?* just deletes ...
recluze's user avatar
  • 453
21 votes
1 answer
2k views

Why doesn't 'find' show this file? [duplicate]

Using find with grep, one can locate files that match a pattern: # find | grep error ./solr-modifiedSolr4/SolrPhpClient/phpdocs/errors.html ./error_log ./includes/classes/error_log However, using ...
dotancohen's user avatar
  • 16.1k
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, ...
Weijun Zhou's user avatar
  • 3,418
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 ...
lonix's user avatar
  • 1,793
10 votes
2 answers
1k views

What is the difference between "*.pl" and *.pl in grep? Why does quoting change the result?

What is the difference between: grep "string" . -r --include *.pl and grep "string" . -r --include "*.pl" The latter includes files in subdirectoried while the former not. Why?
Jim's user avatar
  • 10.2k
10 votes
5 answers
5k views

find not recursive when given a pattern on the command line

Imagine a source tree. There are xml files everywhere. But since there is a XYZ.xml at the root of this tree it won't find my xml files. find -iname *.xml returns ./XYZ.xml instead of ./XYZ.xml ....
Olivier Toupin's user avatar
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_*" ...
TheMeaningfulEngineer's user avatar
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: ...
Smashgen's user avatar
  • 393
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?
tmpbin's user avatar
  • 783
9 votes
3 answers
6k views

ImageMagick on multiple files

I have converted a single file from BMP to PNG with ImageMagick's convert using the command below convert CD\ Front.bmp CD\ Front.png I have many such files, thus I tried: for f in */*.bmp ; do ...
user54619's user avatar
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 $...
phk's user avatar
  • 5,983
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/...
mhulse's user avatar
  • 1,809

15 30 50 per page
1
2 3 4 5