Logo  

CS469 - Linux and Unix Administration and Networking

Displaying exercises/e5/solution/a.sh

#!/bin/bash

# List the files (non-hidden) found in the current directory with a leading
# index (formatted to 3 columns).  ex:
# > ./a.sh
#   1: a.sh
#   2: b.sh
#   3: c.sh

# Initialize an index variable to 1:
let i=1;
# Use a for - in loop with a wildcard to expand all the files in the current
# directory:
for f in *;
do
  # Use printf to format the output, print the index, then the filename.
  printf "%3d: %s\n" $i "$f";
  # Increment the index variable.
  let i++;
done