Code:#!/bin/bash # This shell program prints a tree diagram of # the files in a directory, using recursion. # It is an emulation of the Linux tree command, # which I don't have on my Mac. olddir=$PWD; color="off"; for option in "$@" do case $option in --color ) color="on"; shift;; -* ) shift;; * ) ;; esac done declare -i stackheight=0; # stackheight determines the directory depth. function listfiles { cd "$1"; for file in * do for ((i=0; $i < $stackheight; i++)) do printf "\t"; done # indentation shows the depth of the file if [ -d "$file" ] then if [ $color == "on" ] then printf "\e[34m"; # display directory names in blue fi fi printf "$file\e[0m\n"; if [ -d "$file" ] then stackheight=$stackheight+1; # more indentation listfiles "$file"; # recursive listing of files cd ..; fi done let stackheight=$stackheight-1; # less indentation } listfiles "$1"; cd $olddir; unset i color stackheight;
Last edited by DarkLordoftheMonkeys; 03-10-2010 at 05:32 AM.
Life's too short to be cool. Be a nerd.
Nice! +rep. I think this'll fix your problem with the spaces:
Instead of:
Try this:Code:for file in * do ... done
Can't test it right now, but you can try it.Code:declare -a FILELIST FILELIST="*" for file in ${FILELIST[@]} do ... done
EDIT: Change all your if [ ... ] to if [[ ... ]]; and it'll work for spaces.
sudo rm -rf /
Doesn't matter. I already fixed it weeks ago. Thanks though.
Life's too short to be cool. Be a nerd.
Ah, well you should've posted the solution then.![]()
sudo rm -rf /
I've just edited the original post with the script that works. All I did was put quotation marks around the arguments, and use "$@" instead of $*.
Life's too short to be cool. Be a nerd.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks