Posted on 09-28-2017 11:15 AM
I'm trying to write a bash script that basically stores a file list into an array, loops through the array and then appends something to the files. I.e. loop through a directory and add a . to the beginning to make it hidden.
I know this is fairly simple but I've never really worked with arrays or loops in bash at all.
1. Insert file list into array
2. Loop through array
3. cat something to the file name (would I have to use rn? or is there a way to add something to the filename?)
#!/bin/bash
#get files on desktop and store into array
cd /Users/$3/Desktop/
files=($(ls))
#loop through array and cat something to beginning
for file in files; do
done
Solved! Go to Solution.
Posted on 09-28-2017 12:53 PM
https://www.cyberciti.biz/faq/bash-loop-over-file/
Sample Shell Script To Loop Through All Files
#!/bin/bash
FILES=/path/to/*
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
done
Posted on 09-28-2017 12:53 PM
https://www.cyberciti.biz/faq/bash-loop-over-file/
Sample Shell Script To Loop Through All Files
#!/bin/bash
FILES=/path/to/*
for f in $FILES
do
echo "Processing $f file..."
# take action on each file. $f store current file name
done