Bash script - repeated command
Hi folks,
I have a script which needs following command to repeat confirmation on questions. Code:
...... TIA B.R. satimis |
y dont' you just use the while loop??
|
Just make a seperate file having the questions and then use the script as
Code:
for i in `cat q_file` |
But "cp -r /home/satimis/Document/*" does not suggest the folder name. Thus only copies the "Document/" contents only everytime. So it is not fuctional for what satimis is trying to do.
How about: Code:
for i in `cat q_file` Photo Documents New_Folder Whatever Also I think you want: cp -r /home/satimis/$i/ /home/satimis/Temp/dir1/ Because you want to copie the whole directory and not just the files within right? |
But micxz is missing the dir1, dir2, ... requirement, what about:
Code:
i=0 |
Quote:
|
Quote:
is the same as for i in Document Photo..... In this example, so how am I missing dir1 and dir2... |
If you look closely to the requirements, each copy is going to a different directory:
Document is going to dir1 Photo is going to dir2, your solution is copying all to dir1, so doesn't comply. By the way: Code:
cp -r /home/satimis/$i/ /home/satimis/Temp/dir1/ Code:
/home/satimis/$i /home/satimis/Temp/dir1/ |
Yep your right and I see now about this being pointless. Maybe it was meant to be:
cp -r /home/satimis/$i/ /home/satimis/Temp/ Then maybe there is a point. |
Nope, the same.
The only difference in using a trailing slash is that if $i is a file, an error is triggered and the file is not copied, while with no slash, whether it is a file or a directory doesn't matter, it is copied to the destination directory. For the first remark, I was not arguing of using a separate file for the directory list, which can be a good idea, especially if the file itself need to created by another program, but about the extra level of directories necessary to avoid same name files to be overwritten. |
Hi folks,
Lot of thanks for your suggestions. Hereinunder is the complete script Code:
!/bin/bash Actually this is not a good arrangement. But I’m not allowed to touch the “cdrecord” command Code:
# Create ISO file... Have any other suggestions? TIA B.R. satimis |
Some comments:
you call the cancel command if the user is not willing to add Document of Photo directories. This command's purpose is to cancel a printing job in progress, I'm quite sure it's not what you meant. Why didn't you take or comment any of our suggestions about optimisation ? You last loop isn't testing the validity of the directory entered. |
#!/bin/bash
# Set ISO filename... user=$(whoami) now=$(date +%Y.%m.%d.%R) ISO_File="/home/satimis/To_burn/image_${user}_${now}.iso" dir1=/Document/=/home/satimis/Temp/dir1/ dir2=/Photo/=/home/satimis/Temp/dir2/ # This starts my modifications. Note this is untested! cp_documents() { cp -r /home/satimis/Document/* /home/satimis/Temp/dir1/ } cp_pictures() { cp -r /home/satimis/Pictures/* /home/satimis/Temp/dir1/ } REPLY="B" until [ $REPLY = "" ] do echo "Choose one of the following:" echo echo "[D]ocuments" echo "[P]ictures" echo "[B]oth" echo echo "[Enter] = Exit" echo read case "$REPLY" in "D" | "d" ) # Accept upper or lowercase input. cp_documents ;; "P" | "p" ) cp_pictures ;; "B" | "b" ) cp_documents cp_pictures ;; * ) # Default option. # Do nothing for other keys ;; esac done # The rest of the script is yours # Create ISO file... mkisofs -R -l -graft-points -hide-rr-moved \ $dir1 \ $dir2 \ $list |\ cdrecord dev=ATA:1,0,0 -v -eject - |
Hi /bin/bash,
Tks for your advice. Testing result is as follows; Script Code:
#!/bin/bash Code:
Choose one of the following: Remark: also tried P,p,B,b same result B.R. satimis |
Quote:
Code:
echo |
All times are GMT -5. The time now is 12:41 AM. |