Hello I am trying to write a simple bash script,
the problem I am having is that I want to iterate through the 4th,5th,6th and the 7th files returned from the ls command and then to check if these files have write or read permissions and if they do so, to do a simple copy of these files to another directory. What I've done so far is to check if they have the permissions needed and then if they do, to copy them to the /tmp directory.
My solution:
#!/bin/sh
for f in *
do
if [ -w "$f" ] || [ -r "$f" ]; then
cp $f /tmp
fi
done
The way to get the 4th to 7th file names is through ls | head -7 | tail -4, but how can I iterate specifically though these files names only? Basically how can I make it so the * list in the for loop can be these 4 file names?
Thank you very much.