wildcards in path


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers wildcards in path
# 1  
Old 09-17-2009
wildcards in path

Is there some rule about using wildcards in path? Say I want to create a file, but one of the directories in the path is called 1433d.default and on different machines it will be called <some other string>.default

Code:
touch ~/Library/Application/*.default/myfile

In theory I thought that should work, but it doesn't like the * wildcard. Any help please?
# 2  
Old 09-17-2009
Shell expansion doesn't expand to anything that doesn't exist, so it won't expand that directory unless myfile already exists.

You could do something like
Code:
DIR=~/Library/Application/*.default
if [ ! -d "$DIR" ]
then
        echo "Application defaults not found"
        exit 1
fi

touch "${DIR}/myfile"

# 3  
Old 09-17-2009
no you can't use single touch command to create a file in recursive manner in different dir's
# 4  
Old 09-17-2009
so if I wanted to do an ls or cd or some other command, the wildcard in the path is ok, but not for single touch command?
# 5  
Old 09-17-2009
As I explained, shell globbing can't find things that don't exist yet.
Code:
$ mkdir a b c d
# a/q, b/q, c/q, d/q don't exist yet, so globbing won't work
$ touch [abcd]/q
touch: cannot touch `[abcd]/q':  No such file or directory
$ touch a/q b/q c/d q/q
# Since these files already exist, it will find them
$ touch [abcd]/q
$

But, as I also explained, globbing can find a directory. It can find ~/Library/Application/*.default, just not ~/Library/Application/*.default/file-I-want-to-create-but-does-not-yet-exist.
# 6  
Old 09-19-2009
allright. let's go other way:
if you want to run the command
Code:
touch ~/Library/Application/*.default/myfile

you gotta be sure that shell will expand the wildcard and will find exact location to create the file.
To make sure just type:
Code:
echo ~/Library/Application/*.default

What you got ?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

2. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

3. Shell Programming and Scripting

Generate class path dynamically based on source path

Hi experts, I have multiple file names ending with .jsp located in $SOME_DIR, $SOME_DIR/f1/,$SOME_DIR/f2/test,$SOME_DIR/f3/fa and there are equivalent class files in $SOME_DIR/WEB-INF/classes/_pages,$SOME_DIR/WEB-INF/classes/_pages/_f1,... (0 Replies)
Discussion started by: oraclermanpt
0 Replies

4. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

5. UNIX for Advanced & Expert Users

Wildcards

These 2 websites do a GREAT job of explaining different types of wildcards. I learned about the categories of characters which I never knew about at all. GNU/Linux Command-Line Tools Guide - Wildcards GREP (1 Reply)
Discussion started by: cokedude
1 Replies

6. Shell Programming and Scripting

Executing Commands From Non-Standard Path (Changing user's PATH secretely???)

Hi: I have a requirement as below: I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l). When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies

7. UNIX for Dummies Questions & Answers

wildcards NOT

Hi All Please excuse another straightforward question. When creating a tar archive from a directory I am attempting to use wildcards to eliminate certain filetypes (otherwise the archive gets too large). So I am looking for something along these lines. tar -cf archive.tar * <minus all *.rst... (5 Replies)
Discussion started by: C3000
5 Replies

8. UNIX for Dummies Questions & Answers

ls with wildcards

ok, I'm trying to write a script file that lists files with specific elements in the name into a txt file, it looks like this ls s*.dat > file_names.txt can't figure out whats wrong with that line, any ideas? thanks in advance (10 Replies)
Discussion started by: benu302000
10 Replies

9. UNIX for Dummies Questions & Answers

wildcards

when writing a shell script (bourne) and using a unix command like 'ls' is there anything special you need to do to use a wildcard (like *)? (3 Replies)
Discussion started by: benu302000
3 Replies

10. UNIX for Dummies Questions & Answers

Wildcards in VI

I'm trying to delete lines from a large text file using VI. Every line that I am wanting to delete start with 'S' - all others do not. (A list of users) I've tried using * but doesn't seem to like it...any ideas... Doesn't have to be VI - but I'm better with VI than sed/awk. (8 Replies)
Discussion started by: peter.herlihy
8 Replies
Login or Register to Ask a Question