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

  Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 06:11 AM.. Reason: Please use code tags for data and code samples
Sponsored Links
    #2  
Old Unix and Linux 02-04-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 6 March 2015, 6:04 PM EST
Location: Saskatchewan
Posts: 20,366
Thanks: 872
Thanked 3,567 Times in 3,332 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 Unix and Linux 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 Unix or Linux Image
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 04:18 PM
Run a script when a file is modified/time stamp changed aemunathan Shell Programming and Scripting 3 04-23-2011 04:55 AM
Shell script to find the run time based on log entries? mailtopranesh Shell Programming and Scripting 1 10-31-2010 08:25 PM
Generate array name at run time Korn shell harris2107 Shell Programming and Scripting 2 05-04-2010 11:36 AM
How to run this program with only one input file at a time Prat007 Shell Programming and Scripting 2 01-10-2009 04:27 PM



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