If you need to write a bash script that loop thru directory, then here’s the solution. While writing this bash script to loop thru directory files, i learn something more about single and double quote. So make sure you dont add any double quotes or single quotes to your path when you follow the tutorial below.
To loop thru directory files in bash shell, follow the steps below:-
Advertisements
- Save the code below as file.
12345678FILES=(/home/username/*)for f in "${FILES[@]}"do# FNAME is the only the file name without path# FNAME=`basename $f`# $f store current file name with pathecho "Processing $f file..."done - Change “/home/username” to your own path
- Change the file permission to 700 or 755
- Execute the script and you will be able to loop thru the directory files
Related posts:
How to block .log file using in .htaccess
How to show line number in vi / vim editor
How to create shortcut in Mac OS X
Bootstrap 3: Responsive image align center
CentOS: install yum fastest mirror plugin for faster connection update
How to extract password rar file in command line - Linux
CentOS 7: How to setup TUI Firewall settings?
MySQL: How to add column to existing table
Share this with your friends:-