Skip to content

Conversation

@kasra-dr
Copy link

@kasra-dr kasra-dr commented Mar 18, 2025

Issue

The script output does not match the expected result.
The issue is caused by the incorrect usage of the argument "$1".

Original Code (Buggy)

#!/bin/bash

list_files() {
  for file in $1/*; do
    echo $file
    if [[ -d $file ]]; then
      list_files $file
    fi
  done
}

Fixed Code

#!/bin/bash

read -p "Please enter your directory path: " directory_path
list_files() {
    for file in $(ls "$1"/*); do
    echo $file
    if [[ -d $file ]]; then
      list_files $file
    fi
  done
}

list_files $directory_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant