The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash shell script outthere_3 UNIX for Dummies Questions & Answers 2 01-31-2008 08:13 PM
BASH Shell Script Help -HELP! flamethrower0 Shell Programming and Scripting 2 12-30-2006 01:26 AM
bash shell script and ms-dos space13 Shell Programming and Scripting 1 11-10-2006 07:06 PM
bash shell script norsk hedensk Shell Programming and Scripting 4 08-02-2003 07:27 PM
BASH shell script question ewarmour Shell Programming and Scripting 3 05-24-2002 05:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
one question for bash shell script

Just one question for bash shell script.
In bash script, you can use *.txt to call any files in current folder that ends with .txt, like
rm *.txt
will remove all txt file in current folder.

My question is can you actually remember or use the file name among *.txt, I know file=*.txt will not do this if you call $file later.

Thanks!

Last edited by zx1106; 03-05-2008 at 12:52 AM..
  #2 (permalink)  
Old 03-05-2008
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172
You can use a for loop to iterate through the files

Code:
for f in *
do
    echo $i
    # do whatever you want with the file
done
  #3 (permalink)  
Old 03-05-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
Quote:
Originally Posted by agn View Post
You can use a for loop to iterate through the files

Code:
for f in *
do
    echo $i
    # do whatever you want with the file
done
Thanks a lot!

I tried this method before, but how could I do if I want to change a file among *.txt to *.exe (keep the first part while change the second part)?

Thanks!

Last edited by zx1106; 03-05-2008 at 12:53 AM..
  #4 (permalink)  
Old 03-05-2008
pooga17 pooga17 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 9
i think this will help:-

read ext
#<enter the ext>
for i in `ls *.$ext`
do
echo $i
done
  #5 (permalink)  
Old 03-09-2008
zx1106 zx1106 is offline
Registered User
  
 

Join Date: Mar 2008
Location: U.S.
Posts: 21
Thanks! This certainly works, but you have to type every time. So there is probably a way you do not need to type while can finish this?
  #6 (permalink)  
Old 03-09-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,513
Quote:
Originally Posted by zx1106 View Post
Thanks! This certainly works, but you have to type every time. So there is probably a way you do not need to type while can finish this?
Code:
for file in *ext *txt
do
 ...
done
  #7 (permalink)  
Old 03-05-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
You can use:
Code:
file=`ls *.nex`
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0