Register
It is currently Sat Nov 01, 2014 2:58 am

Bash Script Idea...is it possible?


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Jan 20, 2010 9:30 am   

Joined: Wed Jan 20, 2010 9:26 am
Posts: 2
Hello,

This is my first forum post so be gentle!

Basically, I have a directory with many log files inside. They are all of the same type and of similar naming convention (1-2010-log, 2-2010-log etc.)

I want to create a simple front-end script which will let me access any file in the directory without having to enter the complete path. For example, if I were to simply run the script by typing a simple command then it would ask me which file I wanted to access. After inputting the file name it would open up the file in nano or vi or something similar.

Could I do this with a bash script or would Python or Perl be a better option?

Regards,

Flux


Top
 Profile  
 PostPosted: Fri Jan 22, 2010 10:05 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
A simple bash script would be easy enough to do.
Hopefully this isn't homework, although this is probably too easy for homework, sooo

Code:
#!/bin/bash
ls /path/to/your/directory
read -p "Which file do you want to open? :" this_file
nano /path/to/your/directory/${this_file}
exit 0


ls /path/to/your/directory -- this line lists your directory of files
read -p "Which file do you want to open? :" this_file -- this line allow you to choose your file
nano /path/to/your/directory/${this_file} -- this line opens the file in nano, you could of course change this to vi,emacs, whatever floats your boat. :)


Top
 Profile WWW  
 PostPosted: Sun Jan 24, 2010 9:47 am   

Joined: Wed Jan 20, 2010 9:26 am
Posts: 2
Thanx!

That works great.Just what I was looking for.


Flux


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP