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.

#!/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

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.

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

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

Thanks for correcting me :slight_smile: