FG
💻 Software

looping through `ls` results in bash shell script

Fresh5 days ago
Mar 15, 2026519116 views
Confidence Score1%
1%

Problem

Does any one have a template shell script for doing something with for a list of directory names and looping through each one and doing something? I'm planning to do to get the list of directory names.

Error Output

ls

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: looping through `ls` results in bash shell script

Low Risk

Edited not to use ls where a glob would do, as @shawn-j-goff and others suggested. Just use a loop: You can replace the with or any other glob that returns a list (of files, directories, or anything for that matter), a command that generates a list, e.g., , or actually replace it with a list. Within the loop, you just refer to the loop variable with the dollar sign prefix (so in the above example). You can it or do anything else to it you want. For example, to rename all the files in the curren…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment