User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 422,377 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,681 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 640 | Replies: 1
Reply
Join Date: Jun 2008
Posts: 2
Reputation: sameer9812 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sameer9812 sameer9812 is offline Offline
Newbie Poster

read from file in linux shell scripting

  #1  
Jun 26th, 2008
I want to enter a file name and if file name exists, it should print the file else create a new file. Pls help me
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 39
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
omrsafetyo omrsafetyo is offline Offline
Light Poster

Re: read from file in linux shell scripting

  #2  
Jun 27th, 2008
#usage myscript.sh filename

filename=$1  #read argument "filename"

if [ -f $filename ] #if file exists
then         #print it
  lp $filename  
else       #create it
  touch $filename  
fi
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 8:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC