I want get [4 file name string] from user and pass these parameters to bash script. script should copy files in user home directory.
FYI: each file might be exist or not, might be one of them exist or four of them.
Here is my script, it always copy file1 and seems only one of them [if] execute!
#!/bin/bash
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "File1" ]; then
cp file1 /home/users
else
if [ $T2 = "File2" ]; then
cp file2 /home/users
....
fi
fi
done
"var" is going to start with arg1 and get reassigned to the next in the list each iteration until argn
"T1" is always going to be arg1
"T2" is always going to be arg2
Example:
$ cat /tmp/tryit
#!/usr/bin/bash
for a in "$@"; do
echo $a $1 $2
done
$
$
$ /tmp/tryit a b c d e f
a a b
b a b
c a b
d a b
e a b
f a b
Sorry about confusing you
After these issues I try to export this part in new and separate script, and just cleanup destinations with rm command and then run if(s)
#!/bin/bash
rm -rf /home/users
for var in "$@" ; do
T1=$1
T2=$2
if [ $T1 = "File1" ]; then
cp file1 /home/users
else
if [ $T2 = "File2" ]; then
cp file2 /home/users
....
fi
fi
done