Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created May 17, 2022 10:21
Show Gist options
  • Select an option

  • Save clbarnes/80ae2b90ba3d05ff42e043a7fa65ef94 to your computer and use it in GitHub Desktop.

Select an option

Save clbarnes/80ae2b90ba3d05ff42e043a7fa65ef94 to your computer and use it in GitHub Desktop.
les: ls if it's a directory, less if it's a file
#!/bin/sh
set -e
if [ $# -eq 0 ]; then
>&2 echo "No argument given, using ls"
exec ls
elif [ -d "$1" ]; then
>&2 echo "Directory detected, using ls"
exec ls "$1"
elif [ -f "$1" ]; then
>&2 echo "File detected, using less"
exec less "$1"
else
>&2 echo "No such file or directory"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment