fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate - we can't write files in the home directory;
  4. # so create a temporary directory for our files instead
  5. t=$(mktemp -d -t ideone.XXXXXXXXXXXX) || exit
  6. trap 'rm -rf "$t"' ERR EXIT
  7. cd "$t"
  8.  
  9. touch "foo
  10. bar" "*" "\"sick'ly\""
  11.  
  12. echo "*** naive attempt (broken quoting) ***"
  13. count=0
  14. for file in ./*; do
  15. ((++count))
  16. echo $count: $file
  17. done
  18. echo "$count files total"
  19.  
  20. echo "*** ls (broken) ***"
  21. ls | nl
  22.  
  23. echo "*** find (mildly broken) ***"
  24. find . -type f | nl
  25.  
  26. echo "*** bash array ***"
  27. files=(*)
  28. printf ">>%s<<\n" "${files[@]}"
  29. echo "${#files[@]} files total"
Success #stdin #stdout 0.01s 5352KB
stdin
Standard input is empty
stdout
*** naive attempt (broken quoting) ***
1: ./* ./foo
bar ./"sick'ly"
2: ./foo bar
3: ./"sick'ly"
3 files total
*** ls (broken) ***
     1	*
     2	foo
     3	bar
     4	"sick'ly"
*** find (mildly broken) ***
     1	./"sick'ly"
     2	./*
     3	./foo
     4	bar
*** bash array ***
>>*<<
>>foo
bar<<
>>"sick'ly"<<
3 files total