LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2009, 04:13 PM   #1
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Rep: Reputation: 0
Quick Question


Hey guys,

I looked through some replies to a few old threads and don't understand what I'm doing wrong.

I have an output directory with three files, call them:

Code:
file.bed, file.doc, file.txt
In a bash script, I need to store the name of the file with the .bed extension. I only need the name to be held as a temporary variable.

I have tried about 100 different variations of this command:

NAME=`echo directory/*.bed*`
let NAME='echo directory/*.bed*'
NAME = " 'echo directory/*.bed*' "

etc...

Can someone just put me out of my misery and help me do this simple command?
 
Old 07-02-2009, 04:24 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Your first option *should* work.
Code:
NAME=`echo directory/*.bed*`
If you're using bash/bourne/ksh, that is.

You can also try:
Code:
NAME=`ls directory/*bed`
 
Old 07-02-2009, 04:30 PM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
What's wrong with
NAME=directory/*.bed
?
Or, you don't want the directory name in NAME?
 
Old 07-02-2009, 04:49 PM   #4
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Uncle_Theodore View Post
What's wrong with
NAME=directory/*.bed
?
Or, you don't want the directory name in NAME?
No I do. Do you think perhaps the problem is using *.bed* rather than *.bed?
 
Old 07-02-2009, 04:52 PM   #5
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Well, I'm a bit confused... Could you please elaborate? What result are you expecting and what result do you want?
 
Old 07-02-2009, 05:04 PM   #6
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Uncle_Theodore View Post
Well, I'm a bit confused... Could you please elaborate? What result are you expecting and what result do you want?
Sure.

Let's say again that I have three files in the directory, friends:

Code:
adam.bed, ryan.txt, dave.doc
I want a script to go into this directory, and pick out the only bed file. There will only be one, so I want the script to find "adam.bed" and save that as a variable:

Code:
variable = adam.bed
I just want the name 'adam.bed' save; I don't want the actual file itself grabbed. Later in the script I want to go into that directory and execute a python code with the input 'adam.bed' as part of the extension, but bash doesn't want to recognize my variable. For example, when I say

Code:
echo variable
The result is:

Code:
directory/*.bed
and not:

Code:
directory/adam.bed
See?
 
Old 07-02-2009, 06:07 PM   #7
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Hm... That's strange... Here it works perfectly:

Code:
teddy@office ~$ ls modules/ 
Makefile  Makefile~  hello.c
teddy@office ~$ NAME=modules/*c
teddy@office ~$ echo $NAME
modules/hello.c
Are you using bash as your shell? How do you pass the variable coontent to your python script? Do you use single quotes somewhere?
 
Old 07-02-2009, 07:00 PM   #8
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
I think your problem is your script is not running in the directory above "/directory". Try using the full path (i.e. "/path/to/directory/*.bed*") in your script.
 
Old 07-03-2009, 01:22 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Note that single quotes prevent variable expansion/interpolation, so don't use those.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick Question zybot5785 Linux - Newbie 2 04-10-2007 11:28 AM
Question Concerning ISO's and one quick question. evrae Linux - Software 2 06-21-2004 03:53 AM
samba smb.config question (quick question) TheDOGG Linux - Networking 1 03-02-2004 07:19 AM
quick question jjh221 Linux - Newbie 5 02-24-2004 07:21 PM
Quick question AMDPwred Linux - General 6 01-19-2002 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration