How to take the file name in run time using shell.? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

How to take the file name in run time using shell.?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-04-2013
praveen265 praveen265 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 15 October 2013, 6:00 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
RedHat How to take the file name in run time using shell.?

I want to take the file name as an input to the program and copy that file into new location using shell. Below program is not working properly.

Code:
#!/bin/sh
if [ $file != '']; then
`/usr/bin/perl -pi -e's/(notifications_enabled\s*)(\d+)/$sub = "$1" . ("$2"== "0" ? "1":"0")/e; ' $file`
`cp /script/test/123/$file /etc/hosts/`
fi
case $1 in
'file') echo $file ;;
*) echo "Usage: $0 specify file name" ;;
esac


Last edited by Franklin52; 02-04-2013 at 05:11 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old 02-04-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 21 August 2014, 1:38 PM EDT
Location: Saskatchewan
Posts: 19,231
Thanks: 773
Thanked 3,224 Times in 3,022 Posts
Why are you putting everything in backticks `` ? That is not correct, they are pointless here and probably spew errors too.

You probably want positional parameters here. If someone calls your script with myscript filename then filename will be $1.


Code:
if [ -z "$1" ]
then
        echo "Usage:  $0 filename" >&2
        exit 1
fi

cp "/script/test/123/$1" /etc/hosts/

Sponsored Links
    #3  
Old 02-05-2013
praveen265 praveen265 is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 15 October 2013, 6:00 AM EDT
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
RedHat

Thanks for correcting me
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Connect Oracle using shell script at run time kritibalu Shell Programming and Scripting 4 07-07-2011 03:18 PM
Run a script when a file is modified/time stamp changed aemunathan Shell Programming and Scripting 3 04-23-2011 03:55 AM
Shell script to find the run time based on log entries? mailtopranesh Shell Programming and Scripting 1 10-31-2010 07:25 PM
Generate array name at run time Korn shell harris2107 Shell Programming and Scripting 2 05-04-2010 10:36 AM
How to run this program with only one input file at a time Prat007 Shell Programming and Scripting 2 01-10-2009 03:27 PM



All times are GMT -4. The time now is 09:58 PM.