I have started a few days ago learning how to make scripts in shell. How can I make script thaht takes two arguments ( file name and some directory), if arguments are bad I want to make error alert and if they are correct I want to copy file in given directory? so far I made this:
#!/bin/bash
if [ -d $1 ] ; then
???
done
else
echo $1 NOT DIRECTORY
exit 1
fi
And separate I made a part for checking a file. How to put this together ?
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Use- $0 file"
exit 1
fi
if [ -f $1 ]
then
echo "$1 There is no file with that name"
else
echo "$1 There is no file with that name"
fi
I am new to bash script so I would like to get some help.
if
construct into the first branch of your firstif
(note that thedone
there is wrong; this only applies tofor
loops). And you would check for$# -ne 2
to ensure two arguments are supplied, then use$2
in the file check. Google for "positional parameters" in order to learn more.