LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2009, 06:10 PM   #1
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Rep: Reputation: 15
Question Print file name in BASH


Hi Guys, I want to write a script that returns me name of the files that begin with the specified characters. like
  • abc_tyrie.txt
  • agt_tyuri.txt
  • abc_tui.txt

Script out should be
  • abc_tui.txt
  • abc_tyrie.txt


Can any give me any idea how can I do that? Thanks in Advanced.
 
Old 02-26-2009, 06:14 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
You get the parameter from the command-line, and pass it to ls ... ?
 
Old 02-26-2009, 06:23 PM   #3
waqasdaar
Member
 
Registered: Jan 2009
Location: Stockholm Sweden
Distribution: Ubuntu 9.10
Posts: 57

Original Poster
Rep: Reputation: 15
like if i get the searching characters from the command. Then I can use like this.

ls -l | grep $1*


correct me if I am wrong ?

Thanks in Advanced
 
Old 02-26-2009, 07:30 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Or just simply
Code:
ls -1 ${1}*
you don't really need a script to do this, unless it is just a step in a more complex script.
 
  


Reply



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
bash equivalent of <perl -e 'print time'> teabag_46 Linux - Newbie 2 10-23-2007 03:04 PM
Print section with bash commands xeon123 Programming 1 06-16-2007 03:35 PM
Print-to-file print driver to print PDF Bill Fox Linux - General 3 05-02-2006 04:15 PM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 05:20 PM
Setting up a print to file print driver Bill Fox Linux - General 0 02-26-2005 01:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:40 AM.

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