Looking for suggestions on bash Script
I wrote the following bash script. The goal of the script is to read in a file with a list of file names, then copy those files from one directory to another directory. The list of file names has 197 file names, the source directory has over 3000 plus files.
This worked for me, but I am looking for suggestions on how I can improve this script.
while read line
value=`expr $value + 1`;
image=`sed -n "$value"\p $file`;
cp $sourcedir/"$image" $targetdir;
I am new to bash scripting and I'm not a programmer. I was thrilled I got this to work, and I'll be using it on and off to copy files for various different groups. Doing this got me interested in learning more about bash.
this looks like a one-liner in awk or perl or something like this in bash:
I was looping through each line of the file and using the sed command. Too complicated, your solution is much better. Thanks!
while read line will read config file line by line. You could use it in cp, but you did not do that:
I'd like to add a few comments about the OP script:
1) Please use ***[code][/code] tags*** around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
(Actually, this script is ok, since $file has been previously set to a safe value. But do it anyway to get into the habit! )
b. The line as written is completely unneeded. There's no need set up a fancy file descriptor in most scripts, and even then you'd probably use a different descriptor number.
b. expr is wholly unnecessary in any modern shell. integer-based arithmetic is built-in.
Try a simple "(( value++ ))" instead.
|All times are GMT -5. The time now is 04:14 PM.|