- #!/bin/sh
-
- set -e
-
- if [ -z "$1" ]; then
- # default to current working directory:
- dir="."
- else
- dir="$1"
- fi
-
- # if we got a directory as first param, cd there first:
- if [ -e "$dir" ]; then
- if [ -d "$dir" ]; then
- cd "$dir"
- else
- echo "Not a directory: $dir"
- exit 1
- fi
- else
- echo "No such path: $dir"
- exit 1
- fi
-
- # probably GNU-dependent
- # list (A)lmost all files in
- # current dir, sorted by (t)ime,
- # and return the first (newest):
- basename=$(ls -At | head -1)
-
- # get full path:
- readlink -f "$basename"
|