Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Programming in Linux _ Bourne Shell Scipts

Posted by: philmetz Oct 1 2008, 04:22 AM

Hi
I am trying to create a bourne shell script that will simply copy a file given command line arguments (first = file to copy, 2nd = name of second copy)

How can say copy a file?
I thought I could try:
#!/bin/sh
file1=$1
file2=$2
echo "File 1 is" $file1
echo "File 2 is" $file2

cp file1 file2


but doesnt work

Posted by: philmetz Oct 1 2008, 04:38 AM

Ok i fixed it, forgot to add $
But got a new problem, is there a relationship operator in sh like AND(&&)?
I am trying the following:
#!/bin/sh
file1=$1
file2=$2
if [ $# = 2 && -e $file1]
then
echo "File 1 is" $file1
echo "File 2 is" $file2
cp $file1 $file2
else
echo "ERROR: Not enough command line arguments OR file does not exists!"
fi

So is there a way i can use &&
?

Posted by: michaelk Oct 2 2008, 11:36 AM

Here you go.
http://wiki.linuxquestions.org/wiki/Bash_tips

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)