-
-
Save j03m/177e0e768b570132be95 to your computer and use it in GitHub Desktop.
lc = ls || cat depending on context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If stdin present, assume user meant cat | |
# | |
if [ ! -t 0 ] | |
then | |
cat "$@" | |
exit | |
fi | |
# Find the argument that is file/directory name and test it | |
# to find out if it is an existing directory. Other arguments are | |
# options and thus will begin with an "-". | |
# | |
for v in "$@" | |
do | |
if [ '-' != `echo "$v" | cut -c1 ` ] | |
then | |
if [ -d "$v" ] | |
then | |
# A directory, use "ls". | |
# | |
ls "$@" | |
exit | |
else | |
# Not a directory, use 'cat'. | |
# If this is not a file or a directory then cat will | |
# print an error message: | |
# cat: xxx: No such file or directory | |
# | |
cat "$@" | |
exit | |
fi | |
fi | |
done | |
# No file name provided, assume the user is trying to ls | |
# the working directory | |
# | |
ls "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment