Answer the question
In order to leave comments, you need to log in
How to shorten a bash script?
Hello. With nix systems on "you", it was necessary to write a simple script on the freebsd server to copy some files to the user's home directory in order to slip this script into the task scheduler.
I wrote it as best I can, stupidly, like this:
#!/bin/bash
cp -f /etc/squid/URLs/accessed/access.sorted /home/security/urls/
cp -f /etc/squid/URLs/accessed/oper_kass_url /home/security/urls/
cp -f /etc/squid/URLs/denied/deny.url.uniq /home/security/urls/
cp -f /etc/squid/groups/full.dom /home/security/groups/
cp -f /etc/squid/groups/limit.dom /home/security/groups/
cp -f /etc/squid/groups/oper_kass.dom /home/security/groups/
cp -f /etc/squid/groups/unlim.dom /home/security/groups/
cp -f /etc/squid/squid.conf /home/security/
Answer the question
In order to leave comments, you need to log in
I do not think that this makes sense (nothing will definitely become faster). But you can also write like this:
#!/bin/bash
cp -f /etc/squid/URLs/accessed/{access.sorted,oper_kass_url} /home/security/urls/
cp -f /etc/squid/URLs/denied/deny.url.uniq /home/security/urls/
cp -f /etc/squid/groups/{full.dom,limit.dom,oper_kass.dom,unlim.dom} /home/security/groups/
cp -f /etc/squid/squid.conf /home/security/
If the list of files stays the same forever - then everything is fine, only it would be better to change #!/bin/bash to #!/bin/sh
But if it is expected that the number or location of copied files will at least sometimes change -- I would do like this:
#!/bin/sh
for file in \
/etc/squid/URLs/accessed/access.sorted \
/etc/squid/URLs/accessed/oper_kass_url \
/etc/squid/URLs/denied/deny.url.uniq \
;
do
cp $file /home/security/urls/
done
for file in \
/etc/squid/groups/full.dom \
/etc/squid/groups/limit.dom \
/etc/squid/groups/oper_kass.dom \
/etc/squid/groups/unlim.dom \
;
do
cp $file /home/security/groups/
done
for file in \
/etc/squid/squid.conf \
;
do
cp $file /home/security/urls/
done
Well, you can copy some files by mask .. But why? It won't be any faster.
In my opinion, it's normal. This is not 100500 lines of code, but only 9.
On the other hand, what is this copying for? Maybe just make symlinks?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question