Problem when concatinating wildcard onto file location in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem when concatinating wildcard onto file location in bash script
# 1  
Old 09-28-2010
Problem when concatinating wildcard onto file location in bash script

I am having difficulty with the following script:

Code:
#! /bin/bash

filelist=~/data/${1}*
~/./convertFile $filelist ~/temp/output

Essentially, there are a large number of files in the directory ~/data, each with a four-letter code at the beginning (eg. aaaa001 aaaa002 bbbb001 bbbb002 etc). The argument of this script ($1) is one of these four letter codes.

convertFile is a program written in fortran which takes N arguments, the first N-1 being the location of files that will be converted into one file, which will be outputted to the location in the Nth argument.

When I run (for example):
Code:
./convertFile aaaa* output

from the terminal, the "aaaa*" is expanded out and convertFile acts on every file in the expanded list (as one would expect). However, when I try to write a script to do this in an automated process, it doesn't expand out the files, instead passing the explicit directory location ~/data/aaaa* (where, for example, $1 = 'aaaa'). I don't know what's wrong, is there something awry with how I'm concatenating the strings?
# 2  
Old 09-28-2010
If you get the directory wrong, it won't expand and will stay a literal *.

You can try 'echo $filelist' to see if it's expanding to what you expected.
# 3  
Old 09-28-2010
Thanks, I've double checked it, and the directory is definitely correct.
# 4  
Old 09-28-2010
Try specifying an absolute path instead of ~/

And is it exactly as you've given it here, or is anything quoted?

What does the #!/bin/sh line of your script look like?

You could also try feeding it directly into convertfile as in echo convertfile ~/data/${1}* output
# 5  
Old 09-28-2010
The directory names have been changed here (to make it read easier) but everything else is exactly the same, including the #! line.

Absolute directory names bring no joy, I'm afraid...
# 6  
Old 09-28-2010
Can you post the entire script in one block instead of clips of it?
# 7  
Old 09-28-2010
Quote:
Originally Posted by Corona688
Can you post the entire script in one block instead of clips of it?
That is the entire script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Wildcard in bash script

Hi there, I am pretty new to linux scripting so .. I am writing a script to loop through all my directories of sequence files in order to do stuff with them (trimming, normalizing, stuff that one would do with sequence files). Here I need to pick out files that match each other. The files... (10 Replies)
Discussion started by: jahndavik
10 Replies

2. Shell Programming and Scripting

How to find a existing file location and directory location in Solaris box?

Hi This is my third past and very impressed with previous post replies Hoping the same for below query How to find a existing file location and directory location in solaris box (1 Reply)
Discussion started by: buzzme
1 Replies

3. Shell Programming and Scripting

Difficult problem: Complex text file manipulation in bash script.

I don't know if this is a big issue or not, but I'm having difficulties. I apoligize for the upcoming essay :o. I'm writing a script, similar to a paint program that edits images, but in the form of ANSI block characters. The program so far is working. I managed to save the image into a file,... (14 Replies)
Discussion started by: tinman47
14 Replies

4. Shell Programming and Scripting

Bash script to read file location

I'm writing a bash script that reads a file location from a user, and I'm wondering how to get the script to accept tab to auto complete the directories that are input. (8 Replies)
Discussion started by: Prodiga1
8 Replies

5. Shell Programming and Scripting

wildcard in bash shell script

I tried to use the wildcard '*' in my bash script, but I can not get it work. Here is a simple example (list file names in current directory): ls ./* does not work in my bash script. But it works if I use ls ./ So is there any special syntax to use '*' wildcard in bash script (I tested the... (11 Replies)
Discussion started by: aerosols
11 Replies

6. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

7. Shell Programming and Scripting

concatinating the string in each line of the file

how to concatenate particular string in each line of a file.. root$cat conf check_11043 heartbeat_4345 ---------- if i want to add the string "done" output of the file should be check_11043 done heartbeat_4345 done (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Shell Programming and Scripting

Bash copy file contents into an existing file at a specific location

Hi all I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far: File A line 1 line 2 line 3 line 4 ... (6 Replies)
Discussion started by: gshepherd7
6 Replies

9. UNIX for Dummies Questions & Answers

Bash Wildcard Question

Hi, I am writing a BASH script. In a directory I have a bunch of files of various filename structures. How do I list all the filenames that begin with either a capital or lowercase A or T. Is there one command that could replace the following 4: ls A* ls a* ls T* ls t* Thanks. Mike (3 Replies)
Discussion started by: msb65
3 Replies

10. Shell Programming and Scripting

globbing, $# is too high after wildcard expansion in bash script

How can I pass in an argument such as "*.k" to a bash script without having to double-quote *.k and not having *.k `glob` to match all files in the pattern? I tried using noglob in my script but this didn't work the way I thought it would.. expansion is still occuring, $# is higher than I... (3 Replies)
Discussion started by: zoo591
3 Replies
Login or Register to Ask a Question