0

Im learning bash and I have a question about how to copy files from fatherly folder into another folder when user types "0". (for example from K2 to K1) And I don't know how to do so.

#!/bin/bash
echo $1 $2 $3 $4
K1=$1
K2=$2
if [ $4 -eq "0" ] then
cp -v ../$2/*.{png,bmp,jpg,xcf,pcx} .
cp -v ../$2/*.{png,bmp,jpg,xcf,pcx} ./$1
fi

that's all I wrote, could you help me..?

Jon Clements
  • 138,671
  • 33
  • 247
  • 280

1 Answers1

0

A possible script:

#!/bin/bash
echo -n "Type your number: "
read ANSWER
if [ "$ANSWER" == "0" ] ; then
    # Put here your cp commands
fi
ams
  • 24,923
  • 4
  • 54
  • 75
Claudio
  • 10,614
  • 4
  • 31
  • 71
  • Numeric comparison, not textual? – Jan Hudec Nov 06 '13 at 15:15
  • `[` uses just one `=` for comparison. – Jan Hudec Nov 06 '13 at 15:16
  • ... with `==` it will work in bash, but not in general shell. And there is no reason why this shouldn't work in any POSIX shell. – Jan Hudec Nov 06 '13 at 15:16
  • Always use `=` in `[...]`. If you rely on `==` working, you may as well rely on `[[...]]` working as well. – chepner Nov 06 '13 at 15:21
  • Thank you very much! This works! However, it works only when I write specific folders name in my cp commands,and I need to use arguments for that... First arguments would be the name of the first folder, and the second one would be the name of a fatherly folder. SOrry if these question may seem idiotic, but I'm green at this... Learning! – user2961021 Nov 06 '13 at 20:13