Accepting filename as command line param and writing to it

Hi,

Is it possible to accept a filename as command line parameter and then write to that file using command redirection? i tried the below script.

outputfile=`echo $1`

echo "Writing to file" > 'echo $outputfile'

exit $returncode

but it isnt working. is there any other way to write to a file whose filename is accepted as a parameter?

Try this:

outputfile=$1
echo $outputfile
echo "Writing to file" > $outputfile

Read some scripting tutorials or books.

Regards

i would suggest trying to solve a problem is good.....but after then rectification is also required....so can u please look below my suggestions and try to check why u r solution is having problem...??? can u do it...

File_Name=$1
Path="/xx/yy"

echo " Welcome....." >> $Path/$File_Name

Nope. this doesnt work. infact i had tried this one too

i guess ur code doesn work either..says ksh [programfilename] cannot execute

Show your entire script. Have you make your script executable with chmod?

Regards

HI...its working..

but i dont understand what could be difference between

outputfile=`echo $1`

and

outputfile=$1

This is the only difference in our code.

why do you need `echo $1` ?
Also a better 'practice' in case your parameter has embedded spaces is: outputfile="$1"

Try this out yourself and watch what happens, with backticks:

echo $1
echo `echo $1`
outputfile=`echo $1`
echo $outputfile

With single quotes:

file='echo $outputfile'
echo $file

Regards

thanks Franklin..... :slight_smile: