logoISU  

CS469/569 - Linux and Unix Administration and Networking

Spring 2022

Displaying ./code/02-10/h5/a.sh

#!/bin/bash

# (2 points)
# List the files (non-hidden) found in the current directory with a leading
# index (formatted to three columns).  ex:
# > ./a.sh
#   1: a.sh
#   2: b.sh
#   3: c.sh
#   4: d.sh
#   5: e.sh
#   6: f.sh
#   7: a.sh~

# Initialize an index variable to 1:
let i=1

# Use a for - in loop with a wild-card to expand all the files in the current
# directory:
for file in *; do
    echo "$i: $file";  # but nicer formatting, assume maybe < 1000 files
    # see printf
    let i++;
done

printf "%4s %04d\n" "hi" "42";