Need a bash script that will ask the user: Which Files Would you like to copy?
Then the user would input the filenames (space seperated, all lowercase)
The script would then cp each file to /data/backup/ and also wc the files to std output. (to see how many lines each file has)
Should go something like this...
./easycopy
#!/bin/bash
#easycopy
echo "Which files would you like to copy? (max6)"
read infile1 infile2 ... infile6 (max 6)
echo "Copying"
#For each file input, cp $infileX to /data/backup/
echo "line counting"
#For each file input, wc $infileX
echo "Done"
Are you aware that files may exist that have spaces in their file name?
Wouldn't a loop lend itself as a solution to this request, and an array with the file names?
yes. I am aware that filenames could have spaces. but in this case they will NEVER have spaces, or numbers, or characters. all lower case text, no spaces.
yes a loop would probably be definite solution for all cases, but this case we are just copying a small amount of files (6 or so).
Then, in order to sort of keep control over the loop count, don't deploy single file name variables but have them all in one var. No error checking is done (yet). Try
read ALLFILES
for FN in $ALLFILES
do echo "Copying"
cp $LINE /data/backup/
echo "line counting"
wc -l $LINE
done
echo "Done"
I tryed, then using $FN instead of $LINE for that example....and yes, that is what I needed...seems like it will work great. I'm not sure why the difference...?