recursively call bash script from any directory


/ Published in: Bash
Save to your folder(s)

This snippet determines the path and script name that will need to be called, and then calls that script and passes it parameters.


Copy this code and paste it in your HTML
  1. #!/usr/bin/env bash
  2.  
  3. #this script calls for three variables to be passed to it, a directory, an indent amount, and a file for output.
  4.  
  5. script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  6. script_name=$(basename "$0")
  7. path_to_script=$script_dir/$script_name
  8.  
  9. new_indent="$indent " #this increases the indent amount for the next recursion
  10. new_start_dir="$start_dir/$directoryname" #this sets the next directory
  11. $("$path_to_script" "$new_start_dir" "$new_indent" "$outfile") #this actually calls the same
  12. #script with the updated parameters

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.